-- This is an example off of the wiki. I know browsers are a bit complicated.
-- https://wiki.multitheftauto.com/wiki/CreateBrowser
--In order to render the browser on the full screen, we need to know the dimensions.
local sx,sy = guiGetScreenSize()
--Let's create a new browser in local mode. We will not be able to load an external URL.
local webBrowser = createBrowser(sx,sy,true,false)
--This is the function to render the browser.
function webBrowserRender()
--Render the browser on the full size of the screen.
dxDrawImage(0,0,sx,sy,webBrowser,0,0,0,tocolor(255,255,255,255),true)
end
--The event onClientBrowserCreated will be triggered, after the browser has been initialized.
--After this event has been triggered, we will be able to load our URL and start drawing.
addEventHandler('onClientBrowserCreated',webBrowser,function()
--After the browser has been initialized, we can load our file.
loadBrowserURL(webBrowser,'http://mta/local/html/site.html')
--Now we can start to render the browser.
addEventHandler('onClientRender',root,webBrowserRender)
end)
And here is a more advanced version (that I created on a dime)
-- Create a table of browsers
browsers = {}
-- Then create a function to create the browser
function dxDrawWebBrowser(x,y,w,h,url)
-- creating a table for its data
local self = {}
self.x = x
self.y = y
self.w = w
self.h = h
self.url = url
-- using a toggle for visibility
self.visible = true
-- creating the browser
self.browser = createBrowser(self.x,self.y)
-- creating a draw function for dx
self.draw = function()
dxDrawImage(self.x,self.y,self.x+self.w,self.y+self.h,self.browser,0,0,0,tocolor(255,255,255,255),true)
end
-- inserting it all to a table so we can grab data
table.insert(browsers,self)
end
-- single global event so that we don't keep creating events
addEventHandler('onClientBrowserCreated',resourceRoot,function()
for i,v in pairs(browsers) do
if source == v.browser then
-- loading its url after grabbing its data
loadBrowserURL(source,v.url)
end
end
end)
-- and this is just to put it on the screen..
addEventHandler('onClientRender',resourceRoot,function()
for i,v in pairs(browsers) do
if v.visible == true then
v.draw()
end
end
end)
-- so after all that code we can finally create a browser..
local sx,sy = guiGetScreenSize()
-- using 0.5 to take literally half the screen..
local newbrowser = dxDrawWebBrowser(sx*0.5,sy*0.5,sx*0.5,sy*0.5,'http://www.google.com/') -- there you go.
-- and to change its visibility now just simply do this
newbrowser.visible = false
-- I hope this helped you.