CreateBrowser: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
 
(20 intermediate revisions by 10 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client_function}}
{{Client function}}
{{New feature/item|3.0150|1.5||
This function creates a new web [[Element/Browser|browser]] element.
This function creates a new web [[Element/Browser|browser]] element.
}}
{{Note|You can also enable CEF development tools using [[toggleBrowserDevTools]]}}


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">element createBrowser ( int width, int height, bool isLocal [, bool transparent = false ] )</syntaxhighlight>
<syntaxhighlight lang="lua">element createBrowser ( int width, int height, bool isLocal [, bool transparent = false ] )</syntaxhighlight>
{{OOP||[[Element/Browser|Browser]]}}


===Required Arguments===
===Required Arguments===
*'''width:''' The browser's native width
*'''width:''' The browser's native width. This should be greater than or equal to 1.
*'''height:''' The browser's native height
*'''height:''' The browser's native height. This should be greater than or equal to 1.
*'''isLocal:''' See examples
*'''isLocal:''' Sets whether the browser can only show local content or content from the internet (see examples for more information)
''
 
{{New feature/item|3.0160|1.6||Invalid sizes will be a hard error.}}
 
===Optional Arguments===
===Optional Arguments===
*'''transparent:''' ''true'' if you want the browser transparent, ''false'' for opaque.
*'''transparent:''' ''true'' if you want the browser transparent, ''false'' for opaque.


===Returns===
===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''.
Returns a [[texture]] of the [[browser]] if it was created successfully, ''false'' otherwise. Returns also ''false'', if the user disabled remote pages and ''isLocal'' was set to ''false''.


==Locale Example==
==Local Example==
This example shows you how to create a fullscreen Webbrowser (showing a local html file) without input-handling.
{{Warning|The scheme for local files has changed. Please read [[Local_Scheme_Handler|Local Scheme Handler]] for details.|true}}
This example shows you how to create a fullscreen web browser (showing a local html file) without input-handling.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--In order to render the browser on the full screen, we need to know the dimensions.
--In order to render the browser on the full screen, we need to know the dimensions.
Line 37: Line 44:
function()
function()
--After the browser has been initialized, we can load our file.
--After the browser has been initialized, we can load our file.
loadBrowserURL(webBrowser, "html/site.html")
loadBrowserURL(webBrowser, "http://mta/local/html/site.html")
--Now we can start to render the browser.
--Now we can start to render the browser.
addEventHandler("onClientRender", getRootElement(), webBrowserRender)
addEventHandler("onClientRender", root, webBrowserRender)
end
end
)
)
Line 45: Line 52:


==Remote Example==
==Remote Example==
This example shows you how to create a fullscreen Webbrowser (showing youtube.com) without input-handling.<br>
This example shows you how to create a fullscreen web browser (showing youtube.com) without input-handling.<br>
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 [[cef/requestBrowserDomains|RequestBrowserDomains]].
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|requestBrowserDomains]].
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--In order to render the browser on the full screen, we need to know the dimensions.
--In order to render the browser on the full screen, we need to know the dimensions.
Line 67: Line 74:
loadBrowserURL(webBrowser, "http://www.youtube.com")
loadBrowserURL(webBrowser, "http://www.youtube.com")
--Now we can start to render the browser.
--Now we can start to render the browser.
addEventHandler("onClientRender", getRootElement(), webBrowserRender)
addEventHandler("onClientRender", root, webBrowserRender)
end
end
)
)
Line 74: Line 81:
==See Also==
==See Also==
{{CEF_functions}}
{{CEF_functions}}
[[ar:createBrowser]]
[[en:CreateBrowser]]
[[hu:createBrowser]]
[[RO:CreateBrowser]]

Latest revision as of 20:41, 21 February 2021

This function creates a new web browser element.

[[{{{image}}}|link=|]] Note: You can also enable CEF development tools using toggleBrowserDevTools

Syntax

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

OOP Syntax Help! I don't understand this!

Method: Browser(...)


Required Arguments

  • width: The browser's native width. This should be greater than or equal to 1.
  • height: The browser's native height. This should be greater than or equal to 1.
  • isLocal: Sets whether the browser can only show local content or content from the internet (see examples for more information)

Invalid sizes will be a hard error.

Optional Arguments

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

Returns

Returns a texture of the browser if it was created successfully, false otherwise. Returns also false, if the user disabled remote pages and isLocal was set to false.

Local Example

Dialog-warning.png Warning: The scheme for local files has changed. Please read Local Scheme Handler for details.

This example shows you how to create a fullscreen web browser (showing a local html file) without input-handling.

--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 in local mode. We will not be able to load an external URL.
local webBrowser = createBrowser(screenWidth, screenHeight, true, false)
	
--This is the 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.
--After this event has been triggered, we will be able to load our URL and start drawing.
addEventHandler("onClientBrowserCreated", webBrowser, 
	function()
		--After the browser has been initialized, we can load our file.
		loadBrowserURL(webBrowser, "http://mta/local/html/site.html")
		--Now we can start to render the browser.
		addEventHandler("onClientRender", root, webBrowserRender)
	end
)

Remote Example

This example shows you how to create a fullscreen web browser (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 in remote mode.
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.
--After this event has been triggered, we will be able to 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")
		--Now we can start to render the browser.
		addEventHandler("onClientRender", root, webBrowserRender)
	end
)

See Also