GetBrowserSource: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Client function}} {{New feature/item|3.0150|1.5|7392| This function can be used to retrieve the source code of a website (asynchronously). The size of the source c...")
 
m (Link to the Romanian translation of this page added.)
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Client function}}
{{New feature/item|3.0150|1.5|7392|
{{New feature/item|3.0151|1.5.1|7392|
This function can be used to retrieve the source code of a website (asynchronously). The size of the source code is limited to 2 MiB (remaining bytes are cut).
This function can be used to retrieve the source code of a website (asynchronously). The size of the source code is limited to 2 MiB (remaining bytes are cut).
}}
}}
Line 7: Line 7:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
table getBrowserSource ( function callback )
bool getBrowserSource ( browser webBrowser, function callback )
</syntaxhighlight>
</syntaxhighlight>
{{OOP||[[Element/Browser|browser]]:getSource}}
===Required arguments===
*'''webBrowser:''' The browser element you want to get the source of
*'''callback:''' a callback function with syntax as described below
====Callback syntax====
====Callback syntax====
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function ( string code )
function ( string code )
</syntaxhighlight>
</syntaxhighlight>
{{OOP||[[Element/Browser|Browser]].getSource||getBrowserSource}}


==Returns==
==Returns==
Line 20: Line 23:


==Example==
==Example==
<syntaxhighlight lang="lua">local browser = createBrowser(...)
<syntaxhighlight lang="lua">
local browser = createBrowser(1024,1024,false,false)     --Create Browser


-- Assuming a website has already been loaded
addEventHandler("onClientBrowserCreated",browser,function()
getBrowserSource(function(code)
     loadBrowserURL(browser,"http://www.youtube.com")    --Load URL
     -- Output code
    outputChatBox(code)
end)
end)
addEventHandler("onClientBrowserDocumentReady",browser,function(url)
    local rnt = getBrowserSource(browser,function(code)    --Get Browser Source and Call Function
        outputChatBox(code)                            --Output Code
    end)
    if rnt then
        outputChatBox("Browser Source Got",0,255,0)
    else
        outputChatBox("Failed To Get Browser Source",255,0,0)
    end
end)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{CEF_functions}}
{{CEF_functions}}
[[hu:getBrowserSource]]
[[RO:getBrowserSource]]

Latest revision as of 12:02, 8 April 2020

This function can be used to retrieve the source code of a website (asynchronously). The size of the source code is limited to 2 MiB (remaining bytes are cut).

Syntax

bool getBrowserSource ( browser webBrowser, function callback )

OOP Syntax Help! I don't understand this!

Method: browser:getSource(...)


Required arguments

  • webBrowser: The browser element you want to get the source of
  • callback: a callback function with syntax as described below

Callback syntax

function ( string code )

Returns

Returns true if valid arguments have been passed, false otherwise.

Example

local browser = createBrowser(1024,1024,false,false)      --Create Browser

addEventHandler("onClientBrowserCreated",browser,function()
    loadBrowserURL(browser,"http://www.youtube.com")    --Load URL
end)

addEventHandler("onClientBrowserDocumentReady",browser,function(url)
    local rnt = getBrowserSource(browser,function(code)     --Get Browser Source and Call Function
        outputChatBox(code)                             --Output Code
    end)
    if rnt then
        outputChatBox("Browser Source Got",0,255,0)
    else
        outputChatBox("Failed To Get Browser Source",255,0,0)
    end
end)

See Also