string.JavascriptSafe

From Garry's Mod
Jump to: navigation, search
 string.JavascriptSafe( )

Contents

Description

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

Arguments

string str

The string that should be escaped.

Returns

string

The escaped string.

Examples

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 ) .. "')" )


Personal tools
Navigation