GetBrowserProperty: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Link to the Romanian translation of this page added.)
 
(2 intermediate revisions by the same user not shown)
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 gets a given property of a specified browser.
This function gets a given property of a specified browser.
Line 21: Line 20:


==Example==
==Example==
Todo
<section name="Example" class="client" show="true">
This example creates a browser that displays (youtube.com), adds a button to get the browser property, and displays the web page as a web page or a phone page:
<syntaxhighlight lang="lua">
--[[ Example By MrKAREEM --]]
 
gui = guiCreateWindow(422, 177, 535, 365, "youtube", false)
guiWindowSetSizable(gui, false)
propertyState = guiCreateButton(10, 332, 515, 23, "getBrowserProperty", false, gui) -- Create button to get your browser property
webBrowser = guiCreateBrowser(9, 22, 516, 299, false, false, false, gui) -- Create a web browser, only works with local pages!
 
local theBrowser = guiGetBrowser(webBrowser) -- Get the web browser
 
-- Load our page on browser creation.
addEventHandler("onClientBrowserCreated", theBrowser, function()
showCursor(true)
loadBrowserURL(source, "http://m.youtube.com\\")
end
)
 
 
addEventHandler( "onClientGUIClick", resourceRoot, function ( )
if source == propertyState then
if isBrowserLoading(theBrowser) then return outputChatBox('Please wait until the browser load!',255,0,0) end -- To avoid mistakes
local getType = getBrowserProperty(theBrowser,'mobile') -- Getting the value of the browser property for the "mobile" key
if getType == '0' then -- This checks whether or not the browser appears as a mobile page
setBrowserProperty(theBrowser, "mobile", '1') -- Show the browser as a mobile page
reloadBrowserPage(theBrowser) -- Reload the browser page
guiSetText( gui, 'mobile_page' )
outputChatBox('You are viewing the browser as a mobile page')
elseif getType == '1' then
setBrowserProperty(theBrowser, "mobile", '0') -- Show the browser as a normal page
reloadBrowserPage(theBrowser) -- Reload the browser page
guiSetText( gui, 'web_page' )
outputChatBox('You are viewing the browser as a web page')
end
end
end )
</syntaxhighlight>
</section>


==See also==
==See also==

Latest revision as of 17:32, 8 June 2020

This function gets a given property of a specified browser.

Syntax

bool getBrowserProperty ( browser theBrowser, string key )

OOP Syntax Help! I don't understand this!

Method: browser:getProperty(...)
Counterpart: setBrowserProperty


Required arguments

  • theBrowser: browser element to get the property value of
  • key: The browser property key. It can be:
    • mobile: Surfing the web as mobile

Returns

Returns the value if the property was successfully found, false otherwise.

Example

Click to collapse [-]
Example

This example creates a browser that displays (youtube.com), adds a button to get the browser property, and displays the web page as a web page or a phone page:

--[[ Example By MrKAREEM --]]

gui = guiCreateWindow(422, 177, 535, 365, "youtube", false)
guiWindowSetSizable(gui, false)
propertyState = guiCreateButton(10, 332, 515, 23, "getBrowserProperty", false, gui) -- Create button to get your browser property
webBrowser = guiCreateBrowser(9, 22, 516, 299, false, false, false, gui) -- Create a web browser, only works with local pages!

local theBrowser = guiGetBrowser(webBrowser) -- Get the web browser

-- Load our page on browser creation.
addEventHandler("onClientBrowserCreated", theBrowser, function()
showCursor(true)
loadBrowserURL(source, "http://m.youtube.com\\")
end
)


addEventHandler( "onClientGUIClick", resourceRoot, function ( )
if source == propertyState then
if isBrowserLoading(theBrowser) then return outputChatBox('Please wait until the browser load!',255,0,0) end -- To avoid mistakes
local getType = getBrowserProperty(theBrowser,'mobile') -- Getting the value of the browser property for the "mobile" key
if getType == '0' then -- This checks whether or not the browser appears as a mobile page
setBrowserProperty(theBrowser, "mobile", '1') -- Show the browser as a mobile page
reloadBrowserPage(theBrowser) -- Reload the browser page
guiSetText( gui, 'mobile_page' )
outputChatBox('You are viewing the browser as a mobile page')
elseif getType == '1' then
setBrowserProperty(theBrowser, "mobile", '0') -- Show the browser as a normal page
reloadBrowserPage(theBrowser) -- Reload the browser page
guiSetText( gui, 'web_page' )
outputChatBox('You are viewing the browser as a web page')
end
end
end )

See also