/    Sign up×
Community /Pin to ProfileBookmark

<META> tag access with JavaScript

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

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisJan 13.2003 — [font=monospace]document.getElementsByTagName("META")[/font] returns an array containing all of the META tags in a document.
Copy linkTweet thisAlerts:
@tjmatauthorJan 13.2003 — 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?
Copy linkTweet thisAlerts:
@gil_davisJan 13.2003 — 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.
Copy linkTweet thisAlerts:
@tjmatauthorJan 13.2003 — 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.
Copy linkTweet thisAlerts:
@AntithesisJan 15.2003 — 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.
Copy linkTweet thisAlerts:
@tjmatauthorJan 15.2003 — 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?
Copy linkTweet thisAlerts:
@gil_davisJan 15.2003 — [i]Originally posted by tjmat [/i]

[B] oPopup.document.body.innerHTML = src;

<!-- get META tag here -->

[/B]
[/QUOTE]
Aren't META tags in the HEAD not the BODY?

[font=monospace]mAry = oPopup.document.getElementsByTagName("META")[/font]

should get all the META tags in an array stored as "mAry".
Copy linkTweet thisAlerts:
@tjmatauthorJan 15.2003 — 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.
Copy linkTweet thisAlerts:
@swonJan 16.2003 — 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!
×

Success!

Help @tjmat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...