DHTML/Call

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (wrong choice of template)
(Why did you change this from a PanelFunc to a Func???)
Line 1: Line 1:
{{Func
+
{{PanelFunc
 
|Description=Runs/Executes a string as JavaScript code.
 
|Description=Runs/Executes a string as JavaScript code.
{{Note|This function does '''NOT''' evaluate expression (i.e. allow you to pass variables from JavaScript (JS) to Lua context).<br>Because a return value is nil/no value (a.k.a. void).<br>If you wish to pass/return values from JS to Lua, you may want to use {{LibraryFunction|DHTML|AddFunction}} function to accomplish that job.}}
+
{{Note|This function does '''NOT''' evaluate expression (i.e. allow you to pass variables from JavaScript (JS) to Lua context).<br>Because a return value is nil/no value (a.k.a. void).<br>If you wish to pass/return values from JS to Lua, you may want to use {{ClassFunction|DHTML|AddFunction}} function to accomplish that job.}}
 
{{Note|This function is equivalent to {{ClassFunction|DHTML|QueueJavascript}} <pre>DHTML:QueueJavascript( js ) -- Where DHTML is a DHTML panel.</pre> ([https://github.com/garrynewman/garrysmod/blob/97ee4db09c7e8b503e038567601df76b87a3774a/garrysmod/lua/vgui/dhtml.lua#L76 source]).}}
 
{{Note|This function is equivalent to {{ClassFunction|DHTML|QueueJavascript}} <pre>DHTML:QueueJavascript( js ) -- Where DHTML is a DHTML panel.</pre> ([https://github.com/garrynewman/garrysmod/blob/97ee4db09c7e8b503e038567601df76b87a3774a/garrysmod/lua/vgui/dhtml.lua#L76 source]).}}
|Realm=Client
 
|IsClass=Yes
 
|Parent=DHTML
 
|Name=Call
 
 
}}
 
}}
 
{{Arg
 
{{Arg

Revision as of 11:43, 15 May 2016

 DHTML:Call( )

Contents

DescriptionPanelFunc

Runs/Executes a string as JavaScript code.

NOTE

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.

NOTE This function is equivalent to DHTML:QueueJavascript
DHTML:QueueJavascript( js ) -- Where DHTML is a DHTML panel.
(source).

Arguments

string js

Specify JavaScript code to be executed.

Examples

Example

Shows how to change document.body.innerHTML property by calling this function on DHTML panel.

-- First we create a container, in this case it is a full-screen Derma Frame window.
local dframe = vgui.Create( 'DFrame' )
dframe:SetSize( ScrW(), ScrH() )
dframe:SetTitle( "Garry's Mod Wiki" )
dframe:Center()
dframe:MakePopup() -- Enable keyboard and mouse interaction for DFrame panel.

-- Create a new DHTML panel as a child of dframe, and dock-fill it.
local dhtml = vgui.Create( 'DHTML', dframe )
dhtml:Dock( FILL )
-- Navigate to Garry's Mod wikipedia website.
dhtml:OpenURL( 'https://wiki.garrysmod.com/index.php' )
-- Run JavaScript code.
dhtml:Call( [[document.body.innerHTML = 'HTML changed from Lua using JavaScript!';]] )

-- This does not throw an error/exception, but instead returns nil/no value.
-- That means you can't pass/return values from JavaScript back to Lua context using this function.
local number = dhtml:Call( '22;' )
print( number )

Output:

Inner HTML of document body in DHTML panel is now set to "HTML changed from Lua using JavaScript!".
Personal tools
Navigation