Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can JS detect another frame loaded? 2

0 views
Skip to first unread message

John

unread,
Apr 9, 2000, 3:00:00 AM4/9/00
to
Currently using Martin Honnen's suggestion of
"frameset.onloader" handler to detect if a frame
has been loaded.

Unfortunately, it only works once. If I changed
the src of the frame, the frameset won't trigger
a second time. Is there anything I can do to
get that affect? ie. an onload handler for a frame
no matter how many times the src document for
that frame has changed.

Thanks.

Martin Honnen

unread,
Apr 9, 2000, 3:00:00 AM4/9/00
to

John

unread,
Apr 9, 2000, 3:00:00 AM4/9/00
to
Thanks. Tried the demo.

Doesn't seem to work on NN 4.7:

loading http://www.faqts.com...
loading http://javascript.faqts.com...

I gather it should be:

loading http://www.faqts.com...
loaded ____ in ____
loading http://javascript.faqts.com...
loaded ____ in ____

Doesn't work in NN6 either - but it has an extra priviledge
not granted exception

John

John

unread,
Apr 9, 2000, 3:00:00 AM4/9/00
to
My target browser is NN6 only. I need to parse in
an XML file on demand and use the data in that file
to do some DOM scripting on the main document.

There is currently no XML parsing API in Javascript
(that I am aware of)

I planned to load all requests through a hidden frame.
(At the moment, I'm show the frame for debugging
purposes). In order for it to work properly, the
script needs to know when the frame has loaded
the XML document. The requirement here is
that there be absolutely no scripts in the loading
XML document. Those documents contain pure
XML data. Scripting must all be done externally
in some other frame.

Hence the need for some sort of onload event for
the XML frame and it must work more than once.

Trouble is I haven't been able to detect the onload
event of a frame despite having continually tried for
a whole day.

Because the frameset onload event only occurs
once, it is inadequate for this application.

Thanks for the help so far.

John

Martin Honnen

unread,
Apr 9, 2000, 3:00:00 AM4/9/00
to
I think there is an api in preparation to load xml documents. Ask in the
xml group on news.mozilla.org.
I have written the following code to solve the problem but unfortunately
it only works with IE5 while NN6/mozilla refuse to fire the onload on
the iframe I create. Maybe the concept helps

<HTML>
<HEAD>
<STYLE>
</STYLE>
<SCRIPT>
function FileLoader (url, onload) {
this.id = FileLoader.cnt;
FileLoader.elements[FileLoader.cnt++] = this;
this.url = url;
this.onload = onload;
this.createIFRAME();
setTimeout('FileLoader.elements[' + this.id + '].loadDocument()', 20);
}
function FileLoader_createIFRAME () {
this.frameName = 'FileLoader' + this.id;
if (document.all) {
var html = '';
html += '<IFRAME ID="' + this.frameName + '"';
html += ' NAME="' + this.frameName + '"';
html += ' STYLE="visibility: visible;"';
html += ' SRC="about:blank">';
html += '<\/IFRAME>';
document.body.insertAdjacentHTML('beforeEnd', html);
}
else if (document.getElementById) {
var ifr = document.createElement('IFRAME');
ifr.id = ifr.name = this.frameName;
ifr.style.visibility = 'visible'; // just for testing
ifr.width = 300; ifr.height = 100;
ifr.src = 'about:blank';
document.body.appendChild(ifr);
}
}
FileLoader.prototype.createIFRAME = FileLoader_createIFRAME;
function FileLoader_loadDocument (url) {
if (url)
this.url = url;
this.loaded = false;
this.document = null;
var ifrWin =
document.all ? document.frames[this.frameName] :
window.frames[this.frameName];
var html = '';
html += '<HTML>';
html += '<BODY ONLOAD="';
html += 'alert(event.type);'; // just for testing
html += 'var fl = top.FileLoader.elements[' + this.id + '];';
html += 'fl.loaded = true;';
html += 'fl.document = window.frames[0].document;';
html += 'fl.onload(fl.document);';
html += '"';
html += '>';
html += '<IFRAME SRC="' + this.url + '">';
html += '<\/IFRAME>';
html += '<\/BODY>';
html += '<\/HTML>';
ifrWin.document.open();
ifrWin.document.write(html);
ifrWin.document.close();
}
FileLoader.prototype.loadDocument = FileLoader_loadDocument;
FileLoader.cnt = 0;
FileLoader.elements = new Array();
</SCRIPT>
<SCRIPT>
var fl;
function loadHandler (document) {
if (document.all)
alert(document.all.length)
else
alert(document.getElementsByTagName('*').length);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
<A HREF="javascript: void 0"
ONCLICK="fl = new FileLoader('whatelse.html', loadHandler); return
false;"
>
new FileLoader
</A>
|
<A HREF="javascript: void 0"
ONCLICK="fl.loadDocument('whatever.html'); return false;"
>
load whatever.html
</A>
<BR>
</BODY>
</HTML>

--

0 new messages