GetBrowserURL: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Edited example and deleted needs example warning.)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Client function}}
{{Needs Example}}
{{New feature/item|3.0150|1.5||
{{New feature/item|3.0150|1.5||
This function returns the URL of the specified [[Element/Browser|browser]].
This function returns the URL of the specified [[Element/Browser|browser]].
Line 19: Line 18:


==Example==
==Example==
This example creates a command (/isyoutubeloaded) to check if the browser created have something loaded, if it isnt it loads youtube.
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local sX , sY = guiGetScreenSize()
-- In order to render the browser on a corner, we need to get the dimensions of the screen
local screenWidth, screenHeight = guiGetScreenSize( )


-- Let's create a new browser in remote mode
local window = guiCreateWindow( screenWidth/2, 0, screenWidth/2, screenHeight/2, "Web Browser", false )
local browser = guiCreateBrowser( 0, 28, screenWidth/2, screenHeight/2, false, false, false, window )
local theBrowser = guiGetBrowser( browser ) -- Get the browser element from gui-browser


local guiWindow = guiCreateWindow( 0, 0, sX, sY, "Youtube Application", false )
-- Let's create a new command to check if youtube is loaded
local guiBrowser= guiCreateBrowser( 0, 0, sX, sY, false, false, false, window )
addCommandHandler ( "isyoutubeloaded",
local theBrowser = guiGetBrowser( browser )
    function ()
 
if getBrowserURL(theBrowser) == "" then  -- If the browser didnt load anything yet, load youtube
addEventHandler( "onClientBrowserCreated", theBrowser,
outputChatBox("Youtube isn't loaded yet, loading it now....")
function( )
loadBrowserURL( theBrowser, "https://www.youtube.com/" )
loadBrowserURL( source, "https://www.youtube.com/" )
else -- If the browser loaded something
outputChatBox("Youtube is loaded.")
 
if getBrowserURL(theBrowser) == "" then
outputChatBox("youtube isn't loaded yet.")
end
end
end
    end
)
)
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{CEF_functions}}
{{CEF_functions}}

Revision as of 04:25, 13 September 2017

This function returns the URL of the specified browser.

Syntax

string getBrowserURL ( browser webBrowser )

OOP Syntax Help! I don't understand this!

Method: browser:getURL(...)
Variable: .url
Counterpart: loadBrowserURL


Required Arguments

  • webBrowser: The browser

Returns

Returns the web browser URL.

Example

This example creates a command (/isyoutubeloaded) to check if the browser created have something loaded, if it isnt it loads youtube.

Click to collapse [-]
Client
-- In order to render the browser on a corner, we need to get the dimensions of the screen
local screenWidth, screenHeight = guiGetScreenSize( )

-- Let's create a new browser in remote mode
local window = guiCreateWindow( screenWidth/2, 0, screenWidth/2, screenHeight/2, "Web Browser", false )
local browser = guiCreateBrowser( 0, 28, screenWidth/2, screenHeight/2, false, false, false, window )
local theBrowser = guiGetBrowser( browser ) -- Get the browser element from gui-browser

-- Let's create a new command to check if youtube is loaded
addCommandHandler ( "isyoutubeloaded",
    function ()
		if getBrowserURL(theBrowser) == "" then  -- If the browser didnt load anything yet, load youtube
			outputChatBox("Youtube isn't loaded yet, loading it now....")
			loadBrowserURL( theBrowser, "https://www.youtube.com/" )
		else -- If the browser loaded something
			outputChatBox("Youtube is loaded.")
		end
    end
)

See Also