Coding Cookbook/JavaScript Encode

From Wikibooks, open books for an open world
< Coding Cookbook
Jump to: navigation, search

Encode special characters in a string, so that it can be displayed using JavaScript

[edit] VBScript solution

function JSEncode (sInput)
  JSEncode = sInput
  JSEncode = Replace (JSEncode, chr(0), "")
  JSEncode = Replace (JSEncode, "'", "\'")
  JSEncode = Replace (JSEncode, """", "\""")
  JSEncode = Replace (JSEncode, "&", "\x26")
  end function
Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox
Sister projects
Print/export