CreateBrowser

From Multi Theft Auto: Wiki
Jump to navigation Jump to search

This function creates a new web browser element.

Syntax

element createBrowser ( int width, int height, bool isLocal [, bool transparent = false ] )

Required Arguments

  • width: The browser's native width
  • height: The browser's native height
  • isLocal: See examples

Optional Arguments

  • transparent: true if you want the browser transparent, false for opaque.

Returns

Returns true if the browser element was successfully created, false otherwise. Returns also false, if the user disabled remote pages and isLocal was set to false.

Local Example

--todo

Remote Example

This example shows you how to create a fullscreen Webbrowser (showing youtube.com) without input-handling.
Remember, that youtube.com is on the global whitelist. If you want to load a domain/page that is not on the global whitelist, you have to request it with RequestBrowserDomains.

--In order to render the browser on the full screen, we need to know the dimensions.
local screenWidth, screenHeight = guiGetScreenSize()

--let's create a new browser.
local webBrowser = createBrowser(screenWidth, screenHeight, false, false)
	
--function to render the browser.
function webBrowserRender()
	--Render the browser on the full size of the screen.
	dxDrawImage(0, 0, screenWidth, screenHeight, webBrowser, 0, 0, 0, tocolor(255,255,255,255), true)
end

--The event onClientBrowserCreated will be triggered, after the browser has been initialized.
--Here we can finally load our URL and start drawing.
addEventHandler("onClientBrowserCreated", webBrowser, 
	function()
		--after the browser has been initialized, we can load www.youtube.com
		loadBrowserURL(webBrowser, "http://www.youtube.com")
		--finally start to draw the browser.
		addEventHandler("onClientRender", getRootElement(), webBrowserRender)
	end
)

See Also