Click to See Complete Forum and Search --> : <META> tag access with JavaScript
tjmat
01-13-2003, 10:53 AM
I am trying to get read access to a <META> tag in an HTML document in IE 6.x, using client-side JavaScript. I can't seem to find a way or any reference to the Content of the tag. Anyone seen any JavaScript code that can do this? Again, this is running in IE 6.x
gil davis
01-13-2003, 11:24 AM
document.getElementsByTagName("META") returns an array containing all of the META tags in a document.
tjmat
01-13-2003, 12:40 PM
Gil. Thanks for the info. It works great for my main window. However it leads to my next dilema:
What I am working with is the document of a popup window: as in window.CreatePopup(); I'm trying to look at the <meta> tag of the content of the Popup window. It doesn't seem to have any meta tags or, for that matter, any content in the <head> section. Using GetElementsByTagName("META") in the popup document yields an object with zero length. Same for "title". I'm afraid that IE has some kind of special handling for the content of a Popup. Any thoughts?
gil davis
01-13-2003, 04:59 PM
If the page in the pop-up is not in the same domain, you cannot access anything in it. It's a security thing.
If that is not the case, post a link.
tjmat
01-13-2003, 05:18 PM
Gil:
I suppose it is in the same domain; it is on the same server and is one directory level down from the containing page.
eg: container page: foo.bar.com/sample/main.htm
popup content: foo.bar.com/sample/help/button1.htm.
I've never really understood that security/domain issue.
Antithesis
01-15-2003, 11:31 AM
My guess is that you aren't refrencing the window itself. You need to give it a variable name...the following code worked for me:
var foo = window.open("", "", "");
foo.document.write('<meta>');
var bar = foo.document.getElementsByTagName('meta');
bar was an array with a length of one...if you don't get anything meaningful out of that, then post a link or the code and I'll see what I can do.
tjmat
01-15-2003, 02:12 PM
Antithesis: Here is some of the code:
var oPopup = window.createPopup();
function onDoneDown(src){
oPopup.document.body.innerHTML = src;
<!-- get META tag here -->
oPopup.show(lefter, toper + 7, 170, 150);
}
function openToolTip(aSrc, aX, aY)
{
dwn.startDownload("help/" + aSrc, onDoneDown);
lefter = event.screenX + aX + 12;
toper = event.screenY + aY + 15;
}
It got lost in the shuffle, but I'm working with a Popup object, which has a document property but, for some reason doesn't seem to have META tags, even thought the source document code (aSrc in the code) definitely has META tags. I would like to extract info from the source document, which is contained in the META tags.
Any ideas?
gil davis
01-15-2003, 02:17 PM
Originally posted by tjmat
oPopup.document.body.innerHTML = src;
<!-- get META tag here -->
Aren't META tags in the HEAD not the BODY?
mAry = oPopup.document.getElementsByTagName("META")
should get all the META tags in an array stored as "mAry".
tjmat
01-15-2003, 02:28 PM
Gil, I think you have identified the problem: I'm only loading the BODY, and the HEAD never gets loaded with innerHTML. Unfortunately for me, document.head.innerHTML is not a valid property, though. Nor is document.innerHTML a valid property. It looks like I need to find a different way to load the src document into the popup.
Thanks for the help.
For what do you want to use meta's in a window.open?
If you want it for searchspiders or other searchmachine's it makes no sense cause they don't follow javascripts!