Garry's Mod Wiki

Garry's Mod Wiki

  string string.JavascriptSafe( string str )

Description

Escapes special characters for JavaScript in a string, making the string safe for inclusion in to JavaScript strings.

Arguments

1 string str
The string that should be escaped.

Returns

1 string
The escaped string.

Example

Executes JavaScript on a panel using user input safely.

local user_input = "The user's input lives in this variable" local Panel = vgui.Create( "DHTML" ) Panel:SetURL( "example.com/something.html" ) Panel:Center() Panel:SetSize( 100, 100 ) Panel:RunJavascript( "MyJavaScriptFunction('" .. string.JavascriptSafe( user_input ) .. "')" )

This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.

Page content is automatically updated twice a day. Edits and history are not available.

Last Parsed: Loading...