CanBrowserNavigateForward: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Link to the Romanian translation of this page added.)
Line 20: Line 20:
This example creates a browser that can return to the last and previous pages and can also be refreshed:
This example creates a browser that can return to the last and previous pages and can also be refreshed:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
window = guiCreateWindow(126, 122, 848, 674, "Firechrome", false)
window = guiCreateWindow(126, 122, 848, 674, "browser", false)
guiWindowSetSizable(window, false)
guiWindowSetSizable(window, false)
navigateBackBtn = guiCreateButton(10, 19, 39, 36, "<", false, window)
navigateBackBtn = guiCreateButton(10, 19, 39, 36, "<", false, window)
navigateForwardBtn = guiCreateButton(98, 19, 39, 36, ">", false, window)
navigateForwardBtn = guiCreateButton(98, 19, 39, 36, ">", false, window)
reloadBtn = guiCreateButton(49, 19, 49, 36, "reload", false, window)
addressBar =  guiCreateEdit(137, 19, 701, 36, "", false, window)
addressBar =  guiCreateEdit(137, 19, 701, 36, "", false, window)
guiSetEnabled( addressBar, false )
guiSetEnabled(addressBar,false)
reloadBtn = guiCreateButton(49, 19, 49, 36, "reload", false, window)
webBrowser = guiCreateBrowser(10, 55, 828, 609, false, false, false, window)
browser = guiCreateBrowser(10, 55, 828, 609, false, false, false, window)
local theBrowser = guiGetBrowser(webBrowser)  


-- Load our page on browser creation.
-- Load our page on browser creation.
local theBrowser = guiGetBrowser(browser)
addEventHandler("onClientBrowserCreated", theBrowser,  
addEventHandler("onClientBrowserCreated", theBrowser,  
     function()
     function()
showCursor(true)
         loadBrowserURL(source, "https://forum.mtasa.com/")
         loadBrowserURL(source, "https://forum.mtasa.com/")
     end
     end
)
)


-- This checks to see if the browser can navigate in any direction and enables the back or forward buttons
 
addEventHandler( "onClientBrowserDocumentReady", theBrowser, function( )
addEventHandler( "onClientBrowserDocumentReady", theBrowser, function( url )
    navigateForwardBtn.enabled = (canBrowserNavigateForward(theBrowser))
guiSetText( addressBar, getBrowserURL( theBrowser ) )
    navigateBackBtn.enabled = (canBrowserNavigateBack(theBrowser))
    guiSetText( addressBar, getBrowserURL( theBrowser ) )
end )
end )


Line 48: Line 46:
addEventHandler( "onClientGUIClick", resourceRoot, function ( )
addEventHandler( "onClientGUIClick", resourceRoot, function ( )
     if source == navigateBackBtn then
     if source == navigateBackBtn then
if canBrowserNavigateBack(theBrowser) ~= true then return end -- This checks to see if the browser can navigate to the back
         navigateBrowserBack(theBrowser)
         navigateBrowserBack(theBrowser)
     elseif source == navigateForwardBtn then
     elseif source == navigateForwardBtn then -- This checks to see if the browser can navigate to the forward
if canBrowserNavigateForward(theBrowser) ~= true then return end
         navigateBrowserForward(theBrowser)
         navigateBrowserForward(theBrowser)
     elseif source == reloadBtn then
     elseif source == reloadBtn then

Revision as of 14:47, 8 June 2020

This function checks if the browser can go to the next page.

Syntax

bool canBrowserNavigateForward( browser webBrowser )

Required Arguments

  • webBrowser: The browser you want check for a next page.

Returns

Returns true if the browser can go to the next page, false otherwise.

Example

Click to collapse [-]
Client

This example creates a browser that can return to the last and previous pages and can also be refreshed:

window = guiCreateWindow(126, 122, 848, 674, "browser", false)
guiWindowSetSizable(window, false)
navigateBackBtn = guiCreateButton(10, 19, 39, 36, "<", false, window)
navigateForwardBtn = guiCreateButton(98, 19, 39, 36, ">", false, window)
reloadBtn = guiCreateButton(49, 19, 49, 36, "reload", false, window)
addressBar =  guiCreateEdit(137, 19, 701, 36, "", false, window)
guiSetEnabled(addressBar,false)
webBrowser = guiCreateBrowser(10, 55, 828, 609, false, false, false, window)
local theBrowser = guiGetBrowser(webBrowser) 

-- Load our page on browser creation.
addEventHandler("onClientBrowserCreated", theBrowser, 
    function()
	showCursor(true)
        loadBrowserURL(source, "https://forum.mtasa.com/")
    end
)


addEventHandler( "onClientBrowserDocumentReady", theBrowser, function( url )
guiSetText( addressBar, getBrowserURL( theBrowser ) )
end )

-- This part handles the GUI navigation buttons for the browser.
addEventHandler( "onClientGUIClick", resourceRoot, function ( )
    if source == navigateBackBtn then
	if canBrowserNavigateBack(theBrowser) ~= true then return end -- This checks to see if the browser can navigate to the back
        navigateBrowserBack(theBrowser)
    elseif source == navigateForwardBtn then -- This checks to see if the browser can navigate to the forward
	if canBrowserNavigateForward(theBrowser) ~= true then return end
        navigateBrowserForward(theBrowser)
    elseif source == reloadBtn then
        reloadBrowserPage(theBrowser)
    end
end )

See Also