WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] HTML editor corrupts Javascript (3 posts)

  1. DrDaveHPP
    Member
    Posted 5 years ago #

    I've just run into a problem trying to incorporate a JS ad banner on one of our sites.

    Basically, the WP rendering engine seems to be substituting UTF-8 HTML codes for some of the characters - but only in certain places. Thus some ampersands (&), but not others, are rendered as & and some primes ('), but not others, are rendered as ‘ , causing the JS to fail.

    Here's a cut and paste of a sample of the code as it should be:

    <script type="text/javascript">
    var uri = 'http://impgb.tradedoubler.com/imp?type(js)g(########)a(#######)' + new String (Math.random()).substring (2, 11);
    document.write('<sc'+'ript type="text/javascript" src="'+uri+'" charset="ISO-8859-1"></sc'+'ript>');
    </script>

    And here's how the last line but one is rendered in the page source:

    charset="ISO-8859-1"></sc'+'ript><strong>‘</strong>);

    Has anyone else run into this problem? And if so, has anyone worked out how to fix it?

    Many thanks in advance. If I find a solution myself, I'll come back and say so. :-)

    Dave

  2. DrDaveHPP
    Member
    Posted 5 years ago #

    Sorry, the last line but one didn't come out as I intended - I intended to emphasise the character between the two "strong" tags, which gets rendered as & 8 2 1 6 ;

  3. DrDaveHPP
    Member
    Posted 5 years ago #

    Sorted it with a tweak to the /wp-includes/formatting.php file.

    Adjust the end of existing Line 61:

    ... } elseif (strpos($curl, '<code') !== false || strpos($curl, '<kbd') !== false || strpos($curl, '<style') !== false || strpos($curl, '<script') !== false) {

    so that it ends:

    ... || strpos($curl, '<script') !== false || strpos($curl, 'ript>') !== false || strpos($curl, '//') !== false) {

    Other similar tweaks would no doubt cure other similar problems with overzealous reformatting.

Topic Closed

This topic has been closed to new replies.

About this Topic