WordPress.org

Ready to get started?Download WordPress

Forums

How to add Java Script to comments page? (9 posts)

  1. Tezzer
    Member
    Posted 7 years ago #

    Hi, I would like to add an invisible stats counter (java) to my comments pages. The 2 pages where my comment form is:

    http://friedbrains.com/?p=58

    http://friedbrains.com/?p=58#respond

    I have successfully added it to my index page and page template. I have tried adding it to the comments template, but it doesn't show up in source??? Does anyone know what I am doing wrong or what I need to do?

    Regards Tezzer

  2. spencerp
    Member
    Posted 7 years ago #

    Some reads from here might help maybe:
    http://codex.wordpress.org/Using_Javascript#Javascript_in_Template_Files

    Not sure if ya read that already..but, worth a shot right? =)

    spencerp

  3. Tezzer
    Member
    Posted 7 years ago #

    Spencerp, the following is from that link you gave me:

    "To use Javascript repeatedly within your site, you can either set the call for the Javascript, or the script itself, in the head of your header.php template file, between the meta tags and the style sheet link, no differently than you would if you were using Javascript in any HTML page. To "load" the Javascript file into your site, in the head, add something like this"

    Does this mean that if I paste my java script in the head, without a call to it, it will work?

    Regards Tezzer

  4. spencerp
    Member
    Posted 7 years ago #

    Well, what I was doing before.. was, added the call to it like such (In the header.php):

    <script type="text/javascript" src="/scripts/updatepage.js"></script>

    Then, in my theme's file(s).. added the CALL CODE FOR that specific javascript stuff also.. I'll have to find an example once.. Since my hard drive crash Two weeks ago.. I lost alot of my stuff.. Let me try and find it once.. In the meantime, maybe someone else can help ya..

    spencerp

  5. spencerp
    Member
    Posted 7 years ago #

    Ok, here's what I had done before, of course.. this is an example ONLY.. so, please keep this in mind lol..

    I had made a main Javascript file, for various javasript stuff, just inside ONE file. Here's from a theme's header.php file of mine..

    <!-- JavaScripts -->
    <script language="javascript" type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/javascripts/scripts.js"></script>

    In that: /javascripts/scripts.js file, I had for the Quote Comment plugin:

    /* Quote comment
    ----------------------*/
    function quote(comment, author) {
    theContent = document.getElementById(comment).innerHTML;
    theContent = theContent.replace(/ /g, "");
    theContent = theContent.replace(/<p>/g, "");
    theContent = theContent.replace(/</s*p>/g, "n");
    theContent = theContent.replace(/<br>/g, "")

    if (document.getElementById("comment").value == "") {
    document.getElementById("comment").value += "<strong>" + author + "</strong> said: nn<blockquote>" + theContent + "</blockquote>";
    } else {
    document.getElementById("comment").value += "nn<strong>" + author + "</strong> said: nn<blockquote>" + theContent + "</blockquote>";
    }

    Then in the comments.php file, I had this to call for it:

    <?php if (comments_open()) { ?> <a href="#commentform" title="<?php _e('Quote this comment') ?>" onclick="quote('comment-<?php comment_ID() ?>', '<?php echo($comment->comment_author); ?>')"><?php _e('Quote') ?></a> | <?php } ?>

    I hope this helps maybe.. =/

    spencerp

  6. NuclearMoose
    Member
    Posted 7 years ago #

    What if the visitor has JS disabled in their browser? Won't that affect your counter?

  7. Tezzer
    Member
    Posted 7 years ago #

    Thanks, Spencerp, but that seems a lot of work for what I want. I don't really need my counter on every page (just on my comments pages). I was able to simply cut and paste it into my index and page templates and it works fine there, so all I am really asking for is a way to cut and paste it into my comments pages?

    Regards Tezzer

  8. Tezzer
    Member
    Posted 7 years ago #

    Thanks, Spencerp, I think I have solved my problem now. Or at least I think I have. I was able to paste the java directly into my comments template afterall. I am sorry for causing you work.

    I will test it over the next day and see if it works properly.

    Thanks Tezzer

  9. spencerp
    Member
    Posted 7 years ago #

    Hey, it's ok Tezzer.. It was no trouble at all. ;)=) I hope it works like you want, and let us know how things work too ok? =)

    spencerp

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.