WordPress.org

Ready to get started?Download WordPress

Forums

Javascript in posts (12 posts)

  1. zylstra
    Member
    Posted 7 years ago #

    I have the text replace plugin, http://www.coffee2code.com/archives/2004/06/29/plugin-text-replace/ , installed on my blog. I use it to write javascript into my posts. It works on the main page and individual post pages, but it does NOT work on the category pages. You can see it not work at EuropeanParty.com. Any ideas?

  2. whooami
    Member
    Posted 7 years ago #

    Define not working, do you mean that the js isnt getting loaded?

    thats probably because your using relative paths when you are inserting the js.

    and Ive checked, and thats exacly what you are doing:

    embed.js

    thats relative to what the page being viewed is, so when you are @ http://www.europeanparty.com then this:

    http://www.europeanparty.com/embed.js

    works.

    This doesnt, however:

    http://www.europeanparty.com/city/cannes/embed.js

    use the full path the js file.

  3. zylstra
    Member
    Posted 7 years ago #

    whooami, thank you for looking into it, but you are mistaken on two counts. First, I am using /embed.js which is absolute. Second, http://www.europeanparty.com/city/cannes/ doesn't contain any <script> code in the post code whatsoever.

  4. zylstra
    Member
    Posted 7 years ago #

    Can I offer to pay someone to fix this for me here?

  5. whooami
    Member
    Posted 7 years ago #

    actually No you are wrong.

    'embed.js' is NOT an absolute url.

    Its NO different than calling an image like this:

    <img src="blah.png"> Thats relative to the page being viewed.

    THIS is the same code using an absolute url:

    <img src="http://www.mydomain.com/blah.png">

    http://www.domain.com/embed.js is absolute.

    I'll show you exactly I mean. Please provide EXACTLY what you are putting inside the posts you are making. When im done you can feel free to paypal me. :P

  6. whooami
    Member
    Posted 7 years ago #

    actually, I didnt even need you to paste what you are presently doing.

    Here you are:

    http://bigbox.village-idiot.org/

    Thats the front page

    And now we have:

    http://bigbox.village-idiot.org/archives/category/uncategorized

    Thats inside a category.

    What am I doing that you are not?

    Instead of using this inside the post:

    <script>clip = 54;</script>
    <script src="/embed.js"></script>

    which is using a relative path to embed.js

    I am using this:

    <script>clip = 54;</script>
    <script src="http://bigbox.village-idiot.org/embed.js"></script>

    Which is using the absolute url to embed.js
    You can paypal anytime :)

    As I stated above. The path to files is relative to where the browser is.
    For instance, in my example above, if I had used the relative path to embed.js the server would expect it to be here:

    http://bigbox.village-idiot.org/archives/category/embed.js

    Its not. So you use the full url.

  7. The forward slash means "the root directory". So if the path includes the forward slash, it is relative to the root of the site, not to the current location. Relative to the root is equivalent to an absolute path with the http: and the doamin name.

    If there is no forward slash, the path is relative to the current location.

  8. Zylstra - I believe I have the answer.

    Your main page and individual post templates (probably index.php and single.php) are using the_content and your category page (probably archive.php) is using the_excerpt . This shows a small part of the post text and strips out most tags.

    If you edit your archive.php page and change the_excerpt to the_content, you should see the full content of your posts and your scripts should work.

  9. whooami
    Member
    Posted 7 years ago #

    The forward slash means "the root directory".

    Uh, no it doesnt.

  10. inmobiliaria
    Member
    Posted 7 years ago #

    I think it does

  11. whooami
    Member
    Posted 7 years ago #

    well, Ill be damned, I am sorry, you are absolutely correct. Ive tested that and is in fact true. My apologies for being so stubborn.

  12. zylstra
    Member
    Posted 7 years ago #

    LesBessant, to which email address do I send payment? And how much?

    whooami, glad you see the light! :-)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.