Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Pipkin 4 posts 25 karma points
    Oct 19, 2010 @ 21:39
    Anthony Pipkin
    0

    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?

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Oct 19, 2010 @ 21:53
    Peter Duncanson
    0

    Can you cut and paste the code in for ease? Its possible its something in your javascript and not the XSLT

  • Anthony Pipkin 4 posts 25 karma points
    Oct 19, 2010 @ 22:08
    Anthony Pipkin
    1

    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.

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Oct 19, 2010 @ 22:26
    Peter Duncanson
    2

    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

  • webangelo 107 posts 190 karma points
    Oct 19, 2010 @ 22:30
    webangelo
    0

    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.

  • Anthony Pipkin 4 posts 25 karma points
    Oct 19, 2010 @ 22:51
    Anthony Pipkin
    0

    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?

  • webangelo 107 posts 190 karma points
    Oct 19, 2010 @ 23:10
    webangelo
    1

    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

  • Anthony Pipkin 4 posts 25 karma points
    Oct 19, 2010 @ 23:11
    Anthony Pipkin
    0

    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!

  • webangelo 107 posts 190 karma points
    Oct 19, 2010 @ 23:14
    webangelo
    0

    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.

  • webangelo 107 posts 190 karma points
    Oct 19, 2010 @ 23:15
    webangelo
    0

    Great Job Pete.  HFYR!

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Oct 19, 2010 @ 23:17
    Peter Duncanson
    0

    Cheers webandelo, just one of those nasty bugs that needs a second pair of eyes I guess. Sanity checks rule :)

Please Sign in or register to post replies

Write your reply to:

Draft