• Hi there,

    I’m doing a lot of customisation on my ‘Pages’ (page.php) template – among other things – I am using my own css and some javascript in it.

    Now i’ve got over the editor adding all the extra p-tags by putting my code in through the HTML option in the WYSIWIG editor. But my javascript is not working.

    Does anyone have any ideas on this? Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • I think you have to elaborate a little on this to get good answers.
    What are the extra p-tags?
    What kind of (X)HTML is your theme using? If it is XHTML Strict, any Javascript may have to be included as CDATA.
    Can you provide a link to a page where you use Javascript?

    Thread Starter thomasholmes

    (@thomasholmes)

    Hi petit,

    Just looking at it a bit more – I notice this difference. On a webpage where the code works – the ‘view source’ results in the following:


    document.write('Bookmark on <a href=https://del.icio.us/post?&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+' target="blank">del.icio.us</a>');

    whereas on the page where it isn’t working, the ‘view source’ results in the following:


    document.write(’Bookmark on <a xhref="https://del.icio.us/post?&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title)+'" mce_href="https://del.icio.us/post?&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title)+'" target="blank">del.icio.us</a>‘);

    So wp seems to be interpolating and escaping the ampersands and I dunno what else – looks like a bit of a mess.

    Any ideas on how to fix this?

    I am under the impression that I am using XHTML strict but I could be wrong. I did notice when I tried to validate it – I got all sorts of errors with the javascript. How do you include the javascript in the CDATA?

    I can email you a link to the site if that would help but not keen on publishing a link to it. My email is thomas.holmes at gmail.com

    Thanks for your help petit!

    Thread Starter thomasholmes

    (@thomasholmes)

    Actually just noticed I can edit the post after and remove the address. the site is:

    https://www.limited-edition-prints.org/collage-untitled-series-2005/

    be gentle – its probably a bit of a mess – is in dev.

    thanks…

    just noticed I can edit the post after and remove the address
    Just FYI: it’s not “forever” – there is a time limit (can’t remember how long)

    Thread Starter thomasholmes

    (@thomasholmes)

    EDITED: Corrected for code display

    Thanks for the url moshu!

    Have tried this out – it stops the XHTML validator from giving out about the javascript but the WP Rich editor is still parsing and escaping those characters. In fact it even changes the CDATA declaration:

    <![CDATA[ blah&blah ]]>

    comes out the other side as:

    <!–[CDATA[ blah&blah ]]–>

    So in this particular case what i enter as:


    <![CDATA[ <script type="text/javascript"> document.write('Bookmark on <a href="https://del.icio.us/post?&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'" target="blank">del.icio.us</a>'); document.write(' / <a href="https://www.spurl.net/spurl.php?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href)+'" target="blank">spurl</a>'); document.write(' / <a href="https://www.furl.net/storeIt.jsp?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title)+'" target="blank">furl</a>.'); </script>]]>

    comes out in ‘view source’ as:


    <!--[CDATA[ <script type="text/javascript"> document.write(’Bookmark on <a xhref="https://del.icio.us/post?&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title)+'" mce_href="https://del.icio.us/post?&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title)+'" target="blank">del.icio.us</a>‘); document.write(’ / <a xhref="https://www.spurl.net/spurl.php?title='+encodeURIComponent(document.title)+'&amp;url='+encodeURIComponent(location.href)+'" mce_href="https://www.spurl.net/spurl.php?title='+encodeURIComponent(document.title)+'&amp;url='+encodeURIComponent(location.href)+'" target="blank">spurl</a>‘); document.write(’ / <a xhref="https://www.furl.net/storeIt.jsp?u='+encodeURIComponent(location.href)+'&amp;t='+encodeURIComponent(document.title)+'" mce_href="https://www.furl.net/storeIt.jsp?u='+encodeURIComponent(location.href)+'&amp;t='+encodeURIComponent(document.title)+'" target="blank">furl</a>.’); </script>]]–>

    There is an articvle in the Codex (there is almost everything in the Codex ??
    Using_Javascript – I never used JS that’s why couldn’t remember earlier…

    Thread Starter thomasholmes

    (@thomasholmes)

    Thanks again moshu!

    Looks like switching to php might be the best idea. will have to think about that one…

    I guess you should Thomas. The Rich Editor was never intended to accept Javascript in posts. Normally when you use Javascript, you write general functions that apply to all object ( XHTML nodes ) of a certain kind, and you place or link the script in the (x)html <head>section. This would be in your header.php

    Good luck!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Javascript in Page – Problem’ is closed to new replies.