Get all tags in a famed page with IE5

A

Andrew Poulos

I'm trying to get every tag in a page within a frameset. So far I can
get everything but IE 5 to behave by using:

// in the frame set
window.onload = function() {
mypage = window.frames['mainFrame'];
...
}

getAll = function() {
var allEl = mypage.document.getElementsByTagName(*);
...
}

The getElementsByTagName(*) fails in IE 5 so I tried

var allEl = mypage.document.all;

but, alas, it returns an error.

How can I get a collection of all tags in a page from a frameset in IE 5?


Andrew Poulos
 
V

VK

Wrong frame addressing

frame > frameset
alert (self.top.document.all);

frame > frame
alert (self.top['mainFrame'].document.all);

frameset > frame
Locked for security issues: can be used (and it was used) to bypass
inter-domain frame security model.
So far I can get everything:
window.frames['mainFrame']; !
getElementsByT­agName(*); !
What a sorry wannaby are you using?
 
V

VK

What a sorry wannaby are you using?

Under "wannabe" I meant a browser of course, nothing personal.
 
V

VK

In IE model frameSet doesn't have "frames" collection anymore


my bs ^ 2 (bs in square)
The only weak excuse that I did not use frames for several years by
now.

<html>
<head>
<title>Top Frameset</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script>


function test() {
//alert(self.document.title);
alert(self.frames['f2'].docume­nt.getElementsByTagName('P')[0­].innerHTML);



}


window.onload=test;
</script>
</head>

<frameset cols="50%,*">
<frame name="f1" src="frame1.html">
<frame name="f2" src="frame2.html">
</frameset>


</html>
 
A

Andrew Poulos

VK said:
In IE model frameSet doesn't have "frames" collection anymore



my bs ^ 2 (bs in square)
The only weak excuse that I did not use frames for several years by
now.

<html>
<head>
<title>Top Frameset</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script>


function test() {
//alert(self.document.title);
alert(self.frames['f2'].docume­nt.getElementsByTagName('P')[0­].innerHTML);
Sorry, but you've confused me. In IE 5, from a frameset, instead of doing:
var mypage = window.frames['mainFrame'];
var allEl = mypage.document.all;

I should do:
var allEl = self.frames['mainFrame'].document.all;

Isn't window.frames and self.frames not the say thing?

Andrew Poulos
 
M

Martin Honnen

Andrew said:
I'm trying to get every tag in a page within a frameset. So far I can
get everything but IE 5 to behave by using:

// in the frame set
window.onload = function() {
mypage = window.frames['mainFrame'];
...
}

getAll = function() {
var allEl = mypage.document.getElementsByTagName(*);
...
}

The getElementsByTagName(*) fails in IE 5 so I tried

var allEl = mypage.document.all;

but, alas, it returns an error.

What kind of error? window.document.all since IE 4 gives a collection of
all elements in the document.
 
R

Random

VK wrote a bunch of nonsense, to which Andrew Poulos replied:
Sorry, but you've confused me. In IE 5, from a frameset, instead of doing:
var mypage = window.frames['mainFrame'];
var allEl = mypage.document.all;

I should do:
var allEl = self.frames['mainFrame'].document.all;

Isn't window.frames and self.frames not the say thing?

Yes, you're right, because window === self
And of course he implemented the very DOM methods that you are trying
to account for not having.
Andrew Poulos

I think I see the problem, here.

Lacking a getElementById, you're obviously being forced to use the .all
collection-- that much is readily apparent. But after fiddling with it
a bit, I was a bit miffed to note that given:
<html>
<frameset>
<frame id=frameA src=/test.html>
<frame id=frameB src=/test.html>
</frameset>
</html>


Oddly, the following will be true:
window.document.all === window.frames['frameB'].document.all
window.document.body.innerHTML ===
window.frames['frameB'].document.innerHTML
window.frames[1].all.length == 0 ???


Here was one solution (and yes, I know it's ugly, but it worked for
throwing together a quick test):

<html>
<head>
<script>

function loaded( x ) {
alert( x.body.innerHTML );
}

</script>
<frameset rows=50%,50%>
<frame src=/test.html id=frameA></frame>
<frame src=/test.html id=frameB></frame>
</frameset>
</html>


Then, in the <body> tag of /test.html, I added this:
onload=top.loaded&&top.loaded(window.document)

It worked, but it's a bad way to do it and is very easily broken.




I also found that this worked, which you may find more useful:
<html>
<head>
<script>

function check( ) {
if( window.frames['frameB'].document.readyState == 'complete' )
alert( window.frames['frameB'].document.all.length );

else
setTimeout( check, 250 );
}

</script>
<frameset rows=50%,50%>
<frame src=/test.html id=frameA onload=check()></frame>
<frame src=/test.html id=frameB></frame>
</frameset>
</html>


Apparently, until the document in frameB is actually built in the
browser, certain of its properties will refer to the parent window's
properties, in particular .all and .body

This behaviour is not at all what I would expect.

The onload in the <frame> element will fire as soon as the element is
loaded-- not necessarily the document to which it refers. The second
example above checks the referenced document's readyState every
quarter-second until it comes back as 'complete'. I'm not sure if
..readyState is implemented identically in IE4 -- you'll have to check
that.

Don't know if this information will help lead you to the specific
solution you're looking for, but hopefully it's better than nothing.
 
V

VK

Andrew & Random:

Now you guys are confusing me. Are all three of us talking about IE?
That one from Microsoft?

The code below works perfectly (just use some bogus files for
frame1.html and frame2.html). I'm using Windows XP SP1 + IE 6.0.2800

1) OnLoad fires, as it should, only after *all* frames are loaded (I
tested it on loading msn.com to the right frame, 8 sec delay before
alert).
2) No problem to access any elements in frame f1.
3) Definitely window.document.all !=
window.frames['f2'].docume­nt.all, as it's impossible.

And actually this test case equals to your OP that did *not* work for
you. I suggest to take the code below and try to bring it line by line
(checking after each change) to your current variant.
The problem is (if any) either in some extra coding you did not posted,
or in your *personal* IE.

<html>
<head>
<title>Frameset</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script>
function test() {
var win = self.frames['f1'];
var doc = win.document;
var elm = doc.all;
alert(elm[0].innerHTML);
}
window.onload = test;
</script>
</head>

<frameset cols="50%,*">
<frame name="f1" src="frame1.html">
<frame name="f2" src="frame2.html">
</frameset>
<noframes>
<body bgcolor="#FFFFFF">
<p>No frames text</p>
</body>
</noframes>
</html>
 
A

Andrew Poulos

Martin said:
Andrew said:
I'm trying to get every tag in a page within a frameset. So far I can
get everything but IE 5 to behave by using:

// in the frame set
window.onload = function() {
mypage = window.frames['mainFrame'];
...
}

getAll = function() {
var allEl = mypage.document.getElementsByTagName(*);
...
}

The getElementsByTagName(*) fails in IE 5 so I tried

var allEl = mypage.document.all;

but, alas, it returns an error.


What kind of error? window.document.all since IE 4 gives a collection of
all elements in the document.
The error's solved. You guys were right: I was calling getAll before the
page had loaded. Funnily enough IE6 didn't complain.

Andrew Poulos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top