Garry's Mod Wiki

DHTML:AddFunction

DHTML:AddFunction

  DHTML:AddFunction( string library, string name, function callback )

Description

Defines a Javascript function that when called will call a Lua callback.

Must be called after the HTML document has fully loaded.

Arguments

1 string library
Library name of the JS function you are defining.
2 string name
Name of the JS function you are defining.
3 function callback
Function called when the JS function is called. Arguments passed to the JS function will be passed here.

Example

Prints text from Javascript to the console in color.

-- Create the frame local frame = vgui.Create( "DFrame" ) frame:SetSize( 800, 600 ) frame:Center() -- Create a green color variable local color_green = Color( 0, 255, 0 ) -- Define the Javascript function in the DHTML element local DHTML = vgui.Create( "DHTML", frame ) DHTML:Dock( FILL ) DHTML:OpenURL( "https://wiki.facepunch.com/gmod/DHTML" ) DHTML:AddFunction( "console", "luaprint", function( str ) MsgC( color_green, str ) -- Print the given string end) --This runs our function. Our function could also be called from Javascript on the DHTML's page. DHTML:RunJavascript( "console.luaprint( 'Hello from Javascript!' );" )

Special Pages


Wikis

?

Render Time: 46ms

DB GetPage 27
Generate Html 5
SaveChanges (1) 5
Render Body 0
Render Sidebar 6