Derek Mahar
Derek Mahar

Reputation: 28376

Iterate over framesets in JavaScript?

How can I list all FRAMESET elements in an HTML document using JavaScript? I believe it to be possible to select these elements in the DOM tree because the DOM Inspector plugin for Firefox is able to list all the FRAMESETS in a page.

Upvotes: 3

Views: 6266

Answers (2)

wombleton
wombleton

Reputation: 8376

There's a window.frames collection, if that's what you mean.

EDIT: Ah. For blowing away all frameset elements, getElementsByTagName:

var framesets = document.getElementsByTagName('frameset');
for (var i = 0; i < framesets.length; i++) {
  // optional test for whether framesets[i]'s hatesFreedom attribute is true or false
  framesets[i].parentNode.removeChild(framesets[i]);
}

Or jQuery, obviously:

$('frameset[hatesFreedom=true]').remove();

Upvotes: 5

John
John

Reputation: 13720

try
{
 //window.top.frames[0]
 alert(for i in window.top.frames) {alert('window.top.frames = '+i);}
 alert(for i in window.top.frames[0]) {alert('window.top.frames[0] = '+i);}
}
catch (err)
{
 //top frame is not your domain, break out of frames.
 top.window.location = 'http://localhost/';
}

Upvotes: -2

Related Questions