I’m trying to add a JS script to a project, but I never do this. I’ve tried adding it in the Head tab and separately in the JavaScript tab (w/o tags), but I can’t seem to get it to work.
Some themes move anything entered in the Javascript tab down to the end of the page.
Others keep it in the head section at the top.
Code entered into the Head tab should stay at the top of the page. But sometimes certain Javascript doesn’t like being entered up here. Especially older Javascript; that might be looking for elements on the page.
So it would be best to consult with the documentation for this Javascript and see what it says.
In the case of code like Google Analytics, I know they always tell people to put it at the top of the page, but in theory it works fine anywhere! So try it and see what happens. The browser developer console will usually report problems.
“Undefined” errors would be most synonymous with code that’s not running in a desired order.
An important point - Javascript entered into the Head box needs to be wrapped inside <script> and </script> tags, whereas the same code entered in the Javascript box does not need them. One of those little “gotcha” things that even caught me off guard this morning!
I got in touch with the dev and we got the JS up and running. The only problem now is that the button that it generates clashes with my design.
Is there a way to use a Button stack to trigger the JS window that the full <script> is generating? Basically it pulls up a full size window within the browser and populates video content.
To prevent the link causing the page to jump when it is clicked, you could change your onclick value to
myFunction(); return false;
The double-quotes are surplus. RapidWeaver already adds these for you.
I don’t use Foundation, so you’ll have to wait for someone with experience of that framework to advise you further about this. I don’t know if custom attributes are supported on Foundation buttons or not.
There were some instances in the past whereby some button stacks only took the URL you provided and ignored custom attributes.