Jump to content
Sign in to follow this  
MissT

Adding javascript to Headerscripts Code

Recommended Posts

MissT+    4
MissT

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
Danny    1,327
Danny

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


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
MissT+    4
MissT

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
Danny    1,327
Danny

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.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
MissT+    4
MissT

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
MissT+    4
MissT

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
Danny    1,327
Danny

No problem, happy to help! :D


Please search our forums, before posting!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • chamois_blanc
      By chamois_blanc+
      I am trying to clone a container on a page. It throws the following javascript error:
      function l(b, c, e, f) { var g = m.a.f.get(b, p); if (!c) { if (g) throw Error("You cannot apply bindings multiple times to the same element."); m.a.f.set(b, p, !0) } I would appreciate guidance and a fix. Thank you
    • Jeremiah
      By Jeremiah+
      Error: editing.js?ver=930684:5 Uncaught TypeError: Cannot read property 'getData' of undefined
      I have all of the plugins disabled and I still receive the error.
      Page Editor will not load on page.
       
    • oseehys
      By oseehys+
      Can someone give me a breakthrough out here?
      I have been on the media player for like 5 hours now yet it is still not displaying on my media box or the textbox,
      its a free media player on soundclound
      Great day ahead to the developers out here...
      am trying to install the Toneden media player https://www.toneden.io/player to display my songs on sound cloud, i followed everything on the doc, but obviuosly am missing something i did everything i can for 5 hours yet no breakthrough, am using the textbox as display.
      This is the html script i used, what am i missing here? see it below
        (function() { var script = document.createElement('script') script.type = 'text/javascript'; script.async = true; script.src = 'http://sd.toneden.io/production/toneden.loader.js' var entry = document.getElementsByTagName('script')[0]; entry.parentNode.insertBefore(script, entry); }()); ToneDenReady = window.ToneDenReady || []; ToneDenReady.push(function() { ToneDen.player.create({''enter code here'' dom: '#player', urls: [''https://soundcloud.com/reginaspektor'' ] }); });
    • wesleymusgrove
      By wesleymusgrove
      I'm trying to execute some simple JavaScript inline in the style.less file of my child theme.  But it causes some LESS compiler error and completely breaks the DMS editor so I can't edit anything or use the toolbar on the frontend.
      @all-background-colors: "#D09EC8,#F2DD8B,#84e0cd,#F3904E"; @background-color: color(~`@{all-background-colors}.split(',')[Math.floor(Math.random()*@{all-background-colors}.split(',').length)]`); body { background: @background-color; } On http://less2css.org/, this snippet works and randomly changes the body's background to 1 of the 4 colors in @all-background-colors.
      Even something as simple as this anonymous function breaks the compiler:
      @color: ~`(function(){ return "red"; })()`; body { background: @color; } The only way to fix the DMS editor is to remove the JS from my style.less file, and then edit and save the LESS fallback section in the dashboard.
      I tried setting PL_LESS_DEV in my wp-config.php according to http://www.pagelinestheme.com/dms-custom-less-tips/, but it doesn't clear the cache every page refresh like it's supposed to.
      define('PL_LESS_DEV',true); Is it possible to execute this kind of JavaScript in the style.less file of a DMS child theme?
    • jfsturtz
      By jfsturtz
      Hi again.
       
      I'm aspiring to place an image on a page with a MediaBox, then define an HTML image map (<map>, <area> ...), then define an HTML <canvas> over it, then draw on the canvas with custom javascript.
       
      Before I spring $25 -- is Hooker the right guy for this job?  I know you can't support custom script; I'm fine with that -- I've got it all developed and working in JSFiddle.  I just want to know if Hooker is the right (or at least a workable) way to integrate it into my DMS2 site.
       
      Thanks.
       
      /John
×