I copied the source code in question ( }); to </script> ) via View Source in Chrome and pasted it at http://jdstiles.com/java/cct.html and determined the character causing the error is char coded as 8203.
Ok. Quick bit of sanity checking. Quite right it is popping up. Saved your raw outputted html and viewed it in to trusty Textpad and it renders out a "?" where your character is. Then took a look in your XSLT and if you highlight the whitespace between the }); and the ]]> and cut and paste that into Textpad it renders out a "?" too. So its not a case of your ]]> being converted to your funny character, its more a case of the funny character is already there. Delete all the highlighted whitespace and then add in the newlines/formatting again (only for those three lines) and that should clear it.
Does your Javascript have to be inline or can you put it into a file? If the latter, you can use the umbraco.library:RegisterJavaScriptFile method in XSLT to call it, though you may be trying to avoid using that methodology.
Peter - Thanks for doing that bit of research! I will make the attempt and report back.
Webangelo - I'm not familiar with how you mean to use the RegisterJavaScriptFile, but I am able to put it in an external file. Do you have an example you can point me to for this method?
I actually wrote that before I saw the code you were trying to use, so I wasn't sure of the nature of the JavaScript you were calling. Anyway the RegisterJavaScriptFile lets you register a snippet of JavaScript in the head section only if that XSLT macro is included in the page. So it can reduce overhead (as the JavaScript isn't included on pages that don't need it) but allow you to keep your methods in your Script Directory as a file rather than directly in your XLST. So if you were building an event handler for an object, it might make sense to place the method it in a script file and then only include that script file if needed.
That said, the code you have looks like you need to call it in place, so I don't know if the RegisterJavaScriptFile function would improve things or just add an extra layer of complexity for you. Regardless, here is a link to the wiki on it, but it is rather terse.
Wow! Yeah that must have been one of those rouge characters that got entered from this mac keyboard. Deleted it and it works wonderfully. Thanks so much guys!
And how that is tied in to your issue was the thought of minimizing the code you were calling via the <script><![CDATA[ /* code :) */ ]]></script> to help pinpoint the issue.
Char 8203 Crashing Javascript
I asked this in the #umbraco IRC channel, but thought I may get a more timely response here. Much Thanks!
I have a <script><![CDATA[ /* code :) */ ]]></script> in an XSLT file that is being pulled into a page.
]]> is being replaced with a no space character (char code 8203) and causing the javascript to error out with "Unexpected token ILLEGAL"
How can I correct this?
Can you cut and paste the code in for ease? Its possible its something in your javascript and not the XSLT
Here is the XSLT file. https://gist.github.com/a56f14af8f48b9f64d7c
The error can be seen at http://www.digitalinsurance.com/faqs/health-care-reform.aspx in Chrome, Safari, and IE 9 Beta with the developer tools turned on.
I copied the source code in question ( }); to </script> ) via View Source in Chrome and pasted it at http://jdstiles.com/java/cct.html and determined the character causing the error is char coded as 8203.
Ok. Quick bit of sanity checking. Quite right it is popping up. Saved your raw outputted html and viewed it in to trusty Textpad and it renders out a "?" where your character is. Then took a look in your XSLT and if you highlight the whitespace between the }); and the ]]> and cut and paste that into Textpad it renders out a "?" too. So its not a case of your ]]> being converted to your funny character, its more a case of the funny character is already there. Delete all the highlighted whitespace and then add in the newlines/formatting again (only for those three lines) and that should clear it.
Simple cut and paste mistake by the look?
Pete
Does your Javascript have to be inline or can you put it into a file? If the latter, you can use the umbraco.library:RegisterJavaScriptFile method in XSLT to call it, though you may be trying to avoid using that methodology.
Peter - Thanks for doing that bit of research! I will make the attempt and report back.
Webangelo - I'm not familiar with how you mean to use the RegisterJavaScriptFile, but I am able to put it in an external file. Do you have an example you can point me to for this method?
I actually wrote that before I saw the code you were trying to use, so I wasn't sure of the nature of the JavaScript you were calling. Anyway the RegisterJavaScriptFile lets you register a snippet of JavaScript in the head section only if that XSLT macro is included in the page. So it can reduce overhead (as the JavaScript isn't included on pages that don't need it) but allow you to keep your methods in your Script Directory as a file rather than directly in your XLST. So if you were building an event handler for an object, it might make sense to place the method it in a script file and then only include that script file if needed.
That said, the code you have looks like you need to call it in place, so I don't know if the RegisterJavaScriptFile function would improve things or just add an extra layer of complexity for you. Regardless, here is a link to the wiki on it, but it is rather terse.
http://our.umbraco.org/wiki/reference/umbracolibrary/registerjavascriptfile
--Chris
Wow! Yeah that must have been one of those rouge characters that got entered from this mac keyboard. Deleted it and it works wonderfully. Thanks so much guys!
And how that is tied in to your issue was the thought of minimizing the code you were calling via the <script><![CDATA[ /* code :) */ ]]></script> to help pinpoint the issue.
Great Job Pete. HFYR!
Cheers webandelo, just one of those nasty bugs that needs a second pair of eyes I guess. Sanity checks rule :)
is working on a reply...