GetBrowserProperty

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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