Garry's Mod Wiki

string.JavascriptSafe

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

Page Links


Special Pages


Wikis

?

Render Time: 29ms

DB GetPage 4
Generate Html 3
SaveChanges (1) 8
Render Body 0
Render Sidebar 12