GenoPro Developer Home
GenoPro Home  |  SDK Home  |  Report Generator  |  Support  |  Search  |  Help  |  Site Map

Skip Navigation Links.

Util.JavaScriptEncode Method

The JavaScriptEncode method applies encoding rules to produce a valid string for JavaScript and for HTML code. If your report uses JavaScript code with text from your genealogy tree, then you must use JavaScriptEncode, otherwise the generated HTML code will be incorrect.

In JavaScript, the following characters must be encoded:

Character Encoded Character
\  {backslash} \\
"  {double quote} \"
'  {apostrophe / single quote } \'
{tab} \t
{Returns} / {linefeed} \n

To prevent the encoded string produce errors with HTML code, the JavaScriptEncode method also encodes characters reserved for HTML. After all, most JavaScript-encoded string are used in the context of HTML, and the presence of a reserved HTML character is likely to prevent the browser to render the page.

As a result, the following table displays a summary of the encoded characters by JavaScriptEncode.

Character Encoded Character
\  {backslash} \\
"  {double quote} \x22
'  {apostrophe / single quote } \x27
{tab} \t
{Returns} / {linefeed} \n
{space} \x20
& \x26
< \x3C
> \x3E


HTML Encoding Issues:

You should use the JavaScriptEncode method when you need to insert text from the genealogy tree within JavaScript code.

<body onLoad="javascript:top.document.title='@[Report.Write Util.JavaScriptEncode(i.Name)]@';">

JavaScript Obfuscation:
If you search the web for "JavaScript Encode", you will find many pages describing various techniques for encrypting JavaScript code. The method JavaScriptEncode is not about scrambling a script to prevent reverse engineering, but making sure a string can be used safely with JavaScript and with HTML.

See Also:
FormatString /w {&j} encoding


Copyright ┬ę 1998-2014. All rights reserved. GenoPro┬« and the GenoPro logo are registered trademarks.