• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

How to create a link in the <head> section of BC template?

New Here ,
Feb 05, 2013 Feb 05, 2013

Copy link to clipboard

Copied

Can anyone please explain so that even I can understand the reason why the following script does not work as I would expect?

I am trying to append a line of html code to the <head> section of a Page Template.

<script type="text/javascript">

function loadScript() {

if(window.location.href.indexOf("fish") > -1) {

alert("the url contains the string fish");

var csslink = document.createElement("link");

csslink.setAttribute("rel", "canonical");

csslink.setAttribute("type", "text/css");

csslink.setAttribute("href", "http://www.xyz.com/fish/herring");

document.getElementsByTagName("head")[0].appendChild(csslink);

}

window.onload = loadScript();

</script>

Secondly if one cannot append to the <head> can one append to the <body> ?

Any help appreciated.

Kind regards

PW

TOPICS
eCommerce

Views

423

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 05, 2013 Feb 05, 2013

Copy link to clipboard

Copied

LATEST

Hello peterwulf,

Looks like you're missing a } above the widow.onload. That should fix it.

Hope this helps,

Chad Smith - BC Gurus

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines