Finding largest frame of frameset (and doing DOM stuff in it) in IE

S

Sudrien

I'm writing a bookmarklet that creates a prompt in a iframe in the
current html document. This works (mostly) - except for framesets.

In Firefox, I can loop through the frames, calculating the one with
the largest area, like so:


/* console.warn("uh oh - frameset"); */
frames = document.getElementsByTagName('frame');
var biggest = 0; /* the biggest frame #, by pixel area, is
probably the content. */
for (var i = 1; i < frames.length; i++) {
if ( frames.contentWindow.innerHeight *
frames.contentWindow.innerWidth >
frames[biggest].contentWindow.innerHeight *
frames[biggest].contentWindow.innerWidth) { biggest = i; }
}
/* now we have the biggest frame. can we write to it? */
var head =
frames[biggest].contentDocument.getElementsByTagName('head')[0];
script = document.createElement('script');
script.id = 'makeMark';
script.type = 'text/javascript';
script.src = '...';
head.appendChild(script);


However, IE (or IE7 at least) does not seem to support 'contentWindow'
to the same extent. How can I do the same thing in IE?

Note: this script is run after being added to the current document in
a similar way (get head, append info to head)

-Sud.
 
D

David Mark

I'm writing a bookmarklet that creates a prompt in a iframe in the
current html document. This works (mostly) - except for framesets.

In Firefox, I can loop through the frames, calculating the one with
the largest area, like so:

/* console.warn("uh oh - frameset"); */
frames = document.getElementsByTagName('frame');

This is where you painted yourself into a corner. Use the
window.frames collection instead. It returns window objects, rather
than frame elements.
 
S

Sudrien

This is where you painted yourself into a corner. Use the
window.frames collection instead. It returns window objects, rather
than frame elements.

Got it - I had tried it before, thinking it returned an array ouf
documents. That's why nothing worked....

So here is my revised code.

===

biggest = window.frames.length - 1;
for(var i = window.frames.length; i > 0; i-- ) {
if ( (window.frames[i-1].document.body.clientWidth
* window.frames[i-1].document.body.clientHeight)
(window.frames[biggest].document.body.clientWidth
* window.frames[biggest].document.body.clientHeight))
{
biggest = i-1;
}
}
var script = document.createElement('script');
script.id = 'makeMark';
script.type = 'text/javascript';
script.src = 'http://sudrien.net/bookmark/makemark.js';
window.frames[biggest].document.getElementsByTagName('head')
[0].appendChild(script);

===

Now IE7 does not like the last appendChild. It errors out with "bad
parameter"- but The M$ Script debugger for some reason refuses to show
the file at all.

-Sud.
 

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,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top