META tags with Javascript.
It was three simple roadblocks. tags/getElementsByTagName, .name and .content. I felt stupid by the time I got this working.
Bottom line, I was thinking that META tags were somehow different and special from the DOM. Don't know why, just was particularly stupid this morning. They are, so you can find them in your standard DOM methods.
Then I just had to reference their .name to find the META tag I wanted, and then the .content to find the value.
As Anne pointed out in the comments, this javascript isn't ideal nor perfect. So it still needs work. I just haven't done that work yet. But much thanks to Anne for steering me in the correct direction.
Tagged As Coding, Javascript
Comments are Open (6)
Posted at 10:38 AM
Comments
Anne
You understand that this method is not DOM-compliant I hope. 'document.write' is out of date and so is document.all, which is completely unnecessary for this.
You should use document.createElement and appendChild and so on.
Posted by: Anne | September 17, 2003 01:32 PM
Tony
Dammit. I'll update that. Thanks Anne. I was mostly just force-coding from memory. Didn't even think about compliance. I do believe I'll need the document.all for older IE's. We have a pretty old baseline of browsers that I'm doing this for. Once I get my test platform, I'll try it without. (or just email you directly.)
This is twice now you've given me very clear and correct advice. (or pointed out my error). Keep on doing this and I'll start to develop an inferiority complex. ;)
Posted by: Tony | September 17, 2003 09:07 PM
liorean
Remember that the author might use either http-equiv or name. It might be an idea to check both.
Posted by: liorean | September 21, 2003 06:04 AM
Tony
True. I'll probably put that in to be sure. But I do know exactly how they will put it in, as it is part of the standard set forth. But having it check both is the right thing to do.
Posted by: Tony | September 21, 2003 04:57 PM
Anne
http-equiv is only a equivalent of the server settings if anything is correct. It should actually not be used at all (the http-equiv attribute).
Posted by: Anne | September 22, 2003 10:29 AM
Richard
I tried the code however I recieved the following error [MetaTagList.length: is null or not an object ]
Can you help me ?
Have you updated the code ?
Thanks
Posted by: Richard | March 15, 2004 05:52 PM