Click to See Complete Forum and Search --> : appendChild to <head>
boojum
09-15-2003, 02:47 PM
i want to create a meta tag, set its attributes, and add it into the <head>, but the following doesnt work for me
var imgbaroff=document.createElement('meta');
imgbaroff.setAttribute('httpEquiv','imagetoolbar');
imgbaroff.setAttribute('content','no');
document.head.appendChild(imgbaroff);
boojum
09-15-2003, 03:00 PM
changed it, but still doesnt work. it stalls on the last line
document.head.appendChild(imgbaroff);
is that the right way to append something to the head?
No, a little more complex:
//create META tag
var imgbaroff=document.createElement('meta');
imgbaroff.setAttribute('http-equiv','imagetoolbar');
imgbaroff.setAttribute('content','no');
//find the HEAD
var list=document.documentElement.getElementsByTagName("*");
var tags="";
for(var i=0; i<list.length; i++) {
if(list[i].tagName=="HEAD") {
break;
}
}
var HeadTag=list[i];
//insert META tag
HeadTag.insertBefore(imgbaroff, list[i+1]);
//Has it worked?
for(var i=0; i<list.length; i++) {
if(list[i].tagName=="META" && list[i].getAttribute('http-equiv')=="imagetoolbar") {
alert("META tag added");
}
}
boojum
09-15-2003, 04:47 PM
the script works but the tag isnt doing what its supposed to
The imagetoolbar only works for IE6. The tag may need to be present when the document loads.
Maybe the galleryimg="no" works dynamically (see here (http://www.thesitewizard.com/webdesign/imagetoolbar.shtml))
Znupi
09-23-2006, 11:26 AM
Well, it can be done easier ...
document.documentElement.getElementsByTagName("HEAD")[0].appendChild();
Or, a bit more eye-pleasant:
headTag = document.documentElementsByTagName("HEAD")[0];
headTag.appendChild();
:)