Version User Scope of changes
May 16 2008, 9:35 PM EDT elaine2 242 words added, 127 words deleted
May 16 2008, 8:41 PM EDT elaine2 2 words added

Changes

Key:  Additions   Deletions
Embedding a

The JavaScriptProblem

Embedding event handlerhandlers directly in HTML mayelements resultthat incall JavaScript errorsfunctions duringis pagea load.very Specifically,common JavaScriptpractice. Unfortunately callsMicrosoft thatInternet includeExplorer the6 and 7 have a bug where single quote characterdecimal references ( '' or) will be interpreted as single quote characters ( '' )), willwhen in embedded JavaScript. This can easily cause errorsissues inwhere Internetsingle Explorerquotes 6are andbeing 7used as thatString codeconstants, isfor interpreted.example Unfortunatelywhen thispassing isarguments ato problemJavaScript commonfunctions.

Effectively, the following code:

<a href="#addPage" onclick="WPCAPI.showAddPageDialog('bob&#039;sPage', 'Bob&#039;s Page');">

Will be interpreted acrossas allthe webfollowing userin interfaceInternet development.Explorer:

The
<a solutionhref="#addPage" isonclick="WPCAPI.showAddPageDialog('bob'sPage', to'Bob's renderPage');">

Clearly, anythat argumentswill cause JavaScript errors at riskpage load fortime.


The havingSolution

Make sure any single quotes asin URLJavaScript encoded.argument Then,values toare avoideither encodingescaped mismatchesor withencoded Wetpaint'sappropriately. JavaScriptThis application,must wraphappen before the encodedpage stringis inrendered, JavaScript'si.e. decodeURIComponentat methodcompile sotime itvia willJava, bePHP, unencodedASP.NET, whenetc. passedThere are several options to thechoose listener.from.

Example case
Render an "Addescaped single quote Page"character.<a linkhref="#addPage" foronclick="
WPCAPI.showAddPageDialog(
'bob\'sPage',
'Bob\'s Page'
);
">Add a Page</a>
Render a cellsingle quote decimal reference, withescaping the followingleading attributes:cellId:"&". foo'sbarcellDisplayName:Ordinary TheHTML/XML Officialescaping Foo'swill Barconvert PageCorrectsingle renderedquotes code:to decimal references.<a href="#addPage" onclick="
WPCAPI.showAddPageDialog(
'bobdecodeURIComponent('foo%27\&#039;sbar')sPage',
'BobdecodeURIComponent('The%20Official%20Foo%27\&#039;s%20Bar%20Page'));">s Page'
);
Incorrect
rendered">Add code:a Page</a>
Render a single quote hex reference. URL encoding will convert single quotes to hex references, but an additional JavaScript call will be necessary to decode the string before passing it to the listener.<a href="#addPage" onclick="
WPCAPI.showAddPageDialog(
decodeURIComponent(decodeURIComponent('foo'bob&#039;%27sPage')sbar'),
decodeURIComponent('The OfficialdecodeURIComponent('Bob%27s FooPage'&#039;)
s);
">Add Bara Page'));">Page</a>