Description
The DHTML control wraps the internal Awesomium framework, supports calling Javascript functions from Lua, as well as running Lua from within the HTML. Running Lua code is disabled by default.
Parent
Derives methods, etc not listed on this page from Awesomium.
Events
DHTML:
OnChangeTargetURL(
string url )
Called by HTML panels when the target URL of the frame has changed, this happens when you hover over a link.
DHTML:
OnChangeTitle(
string newTitle )
Called by HTML panels when the title of the loaded page has been changed.
DHTML:
OnDocumentReady(
string url )
Called by HTML panels when the panel's DOM has been set up. You can run JavaScript in here.
Methods
DHTML:
AddFunction(
string library,
string name,
function callback )
Defines a Javascript function that when called will call a Lua callback.
Must be called after the HTML document has fully loaded.
DHTML:
Call(
string js )
Runs/Executes a string as JavaScript code in a panel.
This function does NOT evaluate expression (i.e. allow you to pass variables from JavaScript (JS) to Lua context).Because a return value is nil/no value (a.k.a. void).If you wish to pass/return values from JS to Lua, you may want to use DHTML:AddFunction function to accomplish that job.This function is an alias of DHTML:QueueJavascript (source).
DHTML:
ConsoleMessage(
string msg )
Called when the page inside the DHTML window runs console.log. This can also be called within the Lua environment to emulate console.log. If the contained message begins with RUNLUA: the following text will be executed as code within the Lua environment (this is how Lua is called from DHTML windows).
boolean DHTML:
GetAllowLua()
Returns if the loaded page can run Lua code, set by DHTML:SetAllowLua
DHTML:
QueueJavascript(
string js )
Runs/Executes a string as JavaScript code in a panel.
This function does NOT evaluate expression (i.e. allow you to pass variables from JavaScript (JS) to Lua context).Because a return value is nil/no value (a.k.a. void).If you wish to pass/return values from JS to Lua, you may want to use DHTML:AddFunction function to accomplish that job.If Panel:IsVisible is false, PANEL:Think will NOT run, meaning the Javascript Queue will not be processed.Consider overriding PANEL:Paint to stop the panel from drawing..
DHTML:
SetAllowLua(
boolean allow = false )
Determines whether the loaded page can run Lua code or not. See DHTML for how to run Lua from a DHTML window.
DHTML:
SetScrollbars(
boolean show )
We advise against using this. It may be changed or removed in a future update.
Broken. Use the CSS overflow rule instead.
Sets if the loaded window should display scrollbars when the webpage is larger than the viewing window. This is similar to the CSS overflow rule.
DHTML:
StopLoading()
Stops the loading of the HTML panel's current page.
Awesomium doesn’t work with most HTTPS websites because it only supports up to TLS 1.0.
This and other rendering issues can be rectified by using the x86-64 branch.
Using url/href/src
You might have noticed that Relative File Paths like <img src="/images/picture.jpg">
wont work. There are 3 solutions for that:
asset://
Instead of https://
we use asset://
which will point to our local files.
<img src="asset://garrysmod/materials/example_addon/example.png">
Please don't point towards your Addons folder. Use the File Location where Gmod has your addon files included.
Online
Classic Absolute File Paths still work ... well unless you are offline
or the website is down
or the website uses HTTPS above TLS 1.0
Version.
<img src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png">
Base64 encoding
This will encode your local File into a Base64 String. The String will start with the datatype like data:image/jpeg;base64,
followed by a long chain of characters being the Base64 data.
<img src="data:image/jpeg;base64,LzlqLzRBQ...<!-- base64 data -->">
url("data:image/jpeg;base64,LzlqLzRBQ...<!-- base64 data -->")
Websites like https://www.base64-image.de/ can encode the file for you.
Examples
Example
Example
Creates a DHTML and opens Google inside.
Output: 