WordPress.org

Ready to get started?Download WordPress

Forums

WordPress "texturizes" my javascript ... (14 posts)

  1. blakekr
    Member
    Posted 8 years ago #

    ... even when I have the text control format set to "No Formatting" and "No Character Encoding."

    When I place javascript inside my post even with those enabled, it turns the ampersands into &#138s (or whatever). How do I get around this? It isn't a universal type of javascript I can put in the template.

    Thanks, I appreciate your suggestions!

  2. kickass
    Member
    Posted 8 years ago #

    Are you using the cdata thingies? Wrapping them around javascript makes them "translate literally".

    http://www.w3schools.com/xml/xml_cdata.asp
    http://www.w3.org/TR/REC-html40/appendix/notes.html#notes-specifying-data

  3. blakekr
    Member
    Posted 8 years ago #

    Thanks, K. I tried your suggestions but I'm still not there. I haven't used CDATA before but I tried inserting it the way the w3schools document suggested. For output I got a javascript "syntax error" for the "<![CDATA[" line, and WordPress still texturized the ampersands.

    I wasn't sure what to take from the second document, but I tried escaping the amps with backslashes. I wasn't successful though.

  4. kickass
    Member
    Posted 8 years ago #

    There's more than one way to do the cdata things. I'd google it and see if another way helps. Also, if you're using 2.0 you might try turning off that editor and using the simpler editor in advanced mode.

    And I'm sure vkaryl will be chiming in on this eventually, she's the one who clued me in to there being more than one way to do the cdata stuff.

  5. vkaryl
    Member
    Posted 8 years ago #

    Yup. It depends on the script itself, and sometimes on server settings apparently (which is stupid, but the only thing I could figure out when it worked one way on one server and another way elsewhere - may have something to do with tweaks to apache modules, or the dif between apache and windows servers, though I don't have windows servers at all....)

    This is what I've had luck with (within wp):

    <script type="text/javascript">
    //<![CDATA[
    <!--
    your script code goes here
    // -->
    //]]>
    </script>

    I don't think the {literal}{/literal} tagset will be of any help; then again, if you still have problems and want to try that, here's what works within templating engine pages (which are not wp):

    <script type="text/javascript">
    //<![CDATA[
    {literal}
    <!--
    your script code goes here
    // -->
    {/literal}
    //]]>
    </script>

    One other thing to note: sometimes a bork in a js call (in wp I'm talking about) will happen because the lack of white-space interferes somehow with the parser. Try giving each element its own line.... similar to how I have it shown above.

  6. blakekr
    Member
    Posted 8 years ago #

    Thanks, vkaryl. I didn't get errors with the cdata anymore using your code, but WP STILL went in and converted all my ampersands - ARRRRRGH. I must have one of those hopeless server configs. Thanks for trying, I really appreciate it.

  7. billsaysthis
    Member
    Posted 8 years ago #

    I'm having a similar issue, though without the use of the plugin. According to the codex page (http://codex.wordpress.org/Using_Javascript), I should be able to insert a script call directly in the post. However, when I save the post the call is truncated to

    <script type="text/javascript"> </script>

    IOW, the src="myscript.js?p1=xxx&p2=yyy" is removed.

    Any suggestions for a fix/workaround, or do I need to install Jeff's plugin?

  8. vkaryl
    Member
    Posted 8 years ago #

    Is this a call to an external js file? Or inline? And are you using 2.0, and the wysiwyg?

  9. blakekr
    Member
    Posted 8 years ago #

    I've tried it both ways, inline and external. I'm using 1.5.

    Believe it or not, although this sounds crazy, there seems to be some kind of conflict between the javascript source and some kind of javascript affecting wordpress's browser scroll bar??? The conflict doesn't arise if I call the script as an external SRC file, until I click on the far right-hand scrollbar to move up or down, and then it throws an error -- both in the edit window, and the "view site" side of the page as well. Totally bizarre.

    This doesn't happen at all when I call the script outside of wordpress.

  10. billsaysthis
    Member
    Posted 8 years ago #

    Is this a call to an external js file? Or inline? And are you using 2.0, and the wysiwyg?

    My script is external and I'm using 2.0 (don't know how to turn off wysiwyg other than popping up the HTML box, which doesn't help, so am using it). The script absolutely works when used elswhere and even in a 1.5.2 blog I have inside the firewall here.

  11. vkaryl
    Member
    Posted 8 years ago #

    Turn off wysiwyg in your user page at the bottom if you don't want to use it.

    This sort of thing happens with xml-rpc, video, etc. as well - stripping code I mean. Try a google site: search for xml-rpc, or audioblog, or ryan's fix - should turn up several relevant threads, with some information about mitigating the situation.

  12. vkaryl
    Member
    Posted 8 years ago #

    blakekr - as you may note, this board itself has the same problem as far as unescaped characters. I would say that this is something that only the devs could fix, and I wouldn't venture to make a guess as to how likely that would be.

  13. billsaysthis
    Member
    Posted 8 years ago #

    vkarl, thanks so much, that was exactly what I needed.

  14. vkaryl
    Member
    Posted 8 years ago #

    You're welcome!

Topic Closed

This topic has been closed to new replies.

About this Topic