Jump to content


Photo
- - - - -

Adding javascript to Headerscripts Code

headerscripts javascript

Best Answer Danny , 21 March 2013 - 09:31 AM

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.

Go to the full post


  • Please log in to reply
6 replies to this topic

#1 MissT

MissT

    Super Member

  • Members


  • 233 posts
  • LocationUK
  • Country: Country Flag

Posted 21 March 2013 - 09:11 AM

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?...

 

Please Login or Register to see this Hidden Content

 

Many thanks in advance! :)



#2 Danny

Danny

    Is Awesome!

  • Moderators
  • 17636 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 21 March 2013 - 09:17 AM

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



#3 MissT

MissT

    Super Member

  • Members


  • 233 posts
  • LocationUK
  • Country: Country Flag

Posted 21 March 2013 - 09:25 AM

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.



#4 Danny

Danny

    Is Awesome!

  • Moderators
  • 17636 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 21 March 2013 - 09:31 AM   Best Answer

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.



#5 MissT

MissT

    Super Member

  • Members


  • 233 posts
  • LocationUK
  • Country: Country Flag

Posted 21 March 2013 - 09:40 AM

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');

                        }

});



#6 MissT

MissT

    Super Member

  • Members


  • 233 posts
  • LocationUK
  • Country: Country Flag

Posted 21 March 2013 - 09:49 AM

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.



#7 Danny

Danny

    Is Awesome!

  • Moderators
  • 17636 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 21 March 2013 - 10:07 AM

No problem, happy to help! :D







Also tagged with one or more of these keywords: headerscripts, javascript