Archived

This topic is now archived and is closed to further replies.

  • 0

Adding javascript to Headerscripts Code


Question

Posted · Report post

Hi there,

 

I've been given a bit of javascript code to add to my Pagelines Framework (v 2.0.0.) WP v 3.3.1 website which I thought would go in the Headerscripts Code area...

 

Query(document).ready(function() {

                        var elm = jQuery('#'+document.location.hash.replace('#',''));

                        if (elm.attr('href')) {

                                                elm.addClass('highlighted');

                        }

});

 

I don't know javascript - do I have to put something round the code to add it or save it as a file somewhere else then call it from the Headerscripts code area with something like the following?...

 

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

 

Many thanks in advance! :)

Share this post


Link to post
Share on other sites

6 answers to this question

Posted · Report post

Well you should be able to add the code either way, by adding the code itself to the header scripts or add it to a file, upload that file to your server and then link it like I mentioned above.

Share this post


Link to post
Share on other sites

Posted · Report post

Hi,

 

Adding this to your Header Scripts should work, just remember to use the full URL.

 

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

Also, PageLines 2.0.0 ?

I recommend you perform a backup and upgrade to the latest version which is version 2.4.1

Share this post


Link to post
Share on other sites

Posted · Report post

Hi,

 

There is no url at the moment - that is what I was asking... do I need to save the code I've been given...

 

Query(document).ready(function() {

                        var elm = jQuery('#'+document.location.hash.replace('#',''));

                        if (elm.attr('href')) {

                                                elm.addClass('highlighted');

                        }

});

 

into a file? If so how do I do this?  I take it I can't just paste the code above directly into the Headerscripts Code area?

 

The site is a copy of another site created ages ago so I'm not planning to upgrade at this point in time.

 

Thanks again.

Share this post


Link to post
Share on other sites

Posted · Report post

I added the code itself directly to the headerscript area as it looked like the quickest / most obvious option but when I looked at the site the code was appearing at the very top of the website on screen - so I thought perhaps I need to wrap some code round it.

 

So you are saying the following placed directly in the Headerscript Code should work?...

 

Query(document).ready(function() {

                        var elm = jQuery('#'+document.location.hash.replace('#',''));

                        if (elm.attr('href')) {

                                                elm.addClass('highlighted');

                        }

});

Share this post


Link to post
Share on other sites

Posted · Report post

I've just tried putting <script> and </script> round the code in the Headscripts area and that seems to have done the trick, well no error anyway - now to see if the code added works!

 

Thanks.

Share this post


Link to post
Share on other sites

Posted · Report post

No problem, happy to help! :D

Share this post


Link to post
Share on other sites