Entry
How do I detect when an IFRAME has finished loading in NN6?
Why doesn't the onLoad attribute in an IFRAME tag trigger an event in NN6?
How do I set onload event capturing with IFRAMEs in NN6 in Javascript?
How can I tell when an IFRAME has finished loading in NN6?
Nov 22nd, 2008 01:43
Raj Aryan, John Chena, Steve Thames, Ian Grant,
I have tried to place the onload handler in the IFRAME tag itself, but
it doesn't seem to work in NN6 (this works fine with IE4+). I have
also tried to addEventListener to the node, but this fails as well.
<iframe id="myIFrame"
src="index.html"
height="300"
width="600"
onLoad="handleLoad()"></iframe>
<script language="javascript" type="text/javascript">
<!--
document.getElementsByTagName('iframe')['myIFrame'].addEventListener
("load", handleLoad, false);
// or document.getElementById('myIFrame').addEventListener("load",
handleLoad, false);
// -->
</script>
http://bidgreatlinks.com
I've read elsewhere that I could put an onload event handler into each
source page (referencing a parent window handler function), but that's
not the elegant solution I am looking for. I don't want to have to
remember to put it in a BODY tag every time I want to add content to my
site.
Any help would be greatly appreciated.
Ian Grant
idgrant@pandi.20m.com
------------------------------------------------------------------------
Ian, I don't know if you still need help with this but I found this
when I was trying to solve the same problem. Here is the solution I
came up with:
HTML Page:
<HTML>
<HEAD>
<SCRIPT SRC="version.js"></SCRIPT>
<SCRIPT SRC="urloader.js"></SCRIPT>
<SCRIPT>
function Gotit(DocElem)
{
HTMLText = '<HTML>' + DocElem.innerHTML + '</HTML>';
alert(HTMLText);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
<A HREF="#" ONCLICK="URLoader.Get('symbols.html',Gotit);">load
symbols.html</A>
| <A HREF="#" ONCLICK="URLoader.Get('code.html',Gotit);" >load
code.html</A>
</BODY>
</HTML>
------------------------------------------
version.js:
//**********************************************************************
******
//*
//* File: version.js
//*
//* Title: Browser/JavaScript Version Selection
//*
//* Date: 09/15/01 05:37 PM
//*
//* Description: This script is loaded by any web page that loads
scripts that
//* require it. These methods are used to compare the
required
//* browser or JavaScript version to that needed by the
calling
//* script.
//*
//* Object: Version
//*
//* Private: JavaScript - JavaScript Version
//* Netscape - Netscape Version
//* MSIE - Internet Explorer Version
//*
//* Methods: Version.IE(Version) - true if MSIE Version >= Version
//* Version.JS(Version) - true if JavaScript Version >=
Version
//* Version.NS(Version) - true if Netscape Version >=
Version
//*
//* Synopsis: <HEAD>
//* <SCRIPT LANGUAGE="JavaScript"
SRC="version.js"></SCRIPT>
//* <SCRIPT>
//* var OK = Version.NS(<NSVer>) ||
//* Version.IE(<IEVer>) ||
//* Version.JS(<JSVer>);
//* if (!OK)
//* alert("sorry, can't do it.");
//* </SCRIPT>
//* </HEAD>
//*
//* where: NSVer = Required Netscape Version
//* IEVer = Required Internet Explorer Version
//* JSVer = Required JavaScript Version
//*
//* Developers: SMT Steve Thames, Softlife Consulting, Inc.
//*
//* History: 9/12/01 SMT Created.
//*
//**********************************************************************
******
//*---------------------------------------------*
//* Create the static object and find versions. *
//*---------------------------------------------*
var Version = new Object;
a = navigator.userAgent;
ie = a.indexOf("MSIE");
//*-----------------------------------------------------------------*
//* Netscape - If "Gecko" is found, version follows the last slash. *
//* If no "Gecko", version follows "Mozilla/". *
//* Note: IE also contains "Mozilla/" so its Netscape *
//* only if it does not contain "MSIE". *
//*-----------------------------------------------------------------*
Version.Netscape = a.indexOf("Gecko")+1 ?
parseFloat(a.substring(a.lastIndexOf("/")+1))
: a.indexOf("Mozilla")+1 && !(ie+1) ?
parseFloat(a.substring(a.indexOf("/")+1,a.indexOf
(" ")))
: 0;
//*----------------------------------*
//* MSIE - Format is "MSIE version;" *
//*----------------------------------*
Version.MSIE = ie+1
? parseFloat(a.substring(ie+5,a.indexOf(";",ie+5)))
: 0;
//*-------------------------------------------------------*
//* JavaScript - Version determined by available methods. *
//*-------------------------------------------------------*
Version.JavaScript = window.clearInterval ? 1.2 : window.blur ? 1.1 :
1.0;
delete a;
delete ie;
//*----------------------------*
//* Version Comparison Methods *
//*----------------------------*
Version.IE = function(V) { return((V <= this.MSIE) || (!V &&
this.MSIE) ? true : false); }
Version.JS = function(V) { return( V <=
this.JavaScript ? true : false); }
Version.NS = function(V) { return((V <= this.Netscape) || (!V &&
this.Netscape) ? true : false); }
--------------------------------------------
usloader.js
//**********************************************************************
*****
//*
//* File: urloader.js
//*
//* Title: Retrieve URLs into JavaScript Variables
//*
//* Date: 09/15/01 05:31 PM
//*
//* Object: URLoader
//*
//* Description: A static object that provides for the loading of URLs
to
//* JavaScrict through an intermediate IFRAME.
//*
//* This script has been tested using NN6+ and IE5+. It
must be
//* modified to use a LAYER, as well, in order to work
with NN4+.
//*
//* NN6+ will recognize the onload event handler of the
IFRAME
//* but will not actually load the URL while the script is
running.
//* IE5+ does not process the onload event for the IFRAME
but will
//* set the readyState document property to "complete". A
//* setTimeout() is used to call a function that will
check the
//* readyState value and then call the onload event. This
also
//* stops the running script to allow for NN6 to load the
URL and
//* trigger the onload event. Since NN6 does not set the
//* readyState property, this method is transparent NN6+
and IE5+.
//*
//* Since this object adds a new IFRAME element to the
document,
//* the Get() method must not be called before the
document is
//* fully loaded.
//*
//* Private: Frame - IFRAME Element
//* OnLoad - Onload Callback Function
//* Timeout - setTimeout() ID
//*
//* Methods: URLoader.Get - Load URL
//*
//* Required: version.js - Check Browser/JavaScript Versions
//*
//* Synopsis: <HEAD>
//* <SCRIPT LANGUAGE="JavaScript"
SRC="version.js"></SCRIPT>
//* <SCRIPT LANGUAGE="JavaScript"
SRC="urloader.js"></SCRIPT>
//* <SCRIPT>
//* function ShowSource(DocElem)
//* {
//* alert('<HTML>' + DocElem.innerHTML + '</HTML>');
//* }
//* </SCRIPT>
//* </HEAD>
//* </BODY>
//* <A HREF="#" ONCLICK="URLoader.Get
('MyDoc.html',ShowSource)">
//* Show me the source of 'MyDoc.html'</A>
//* </BODY></HEAD>
//*
//* Developers: SMT Steve Thames, Softlife Consulting, Inc.
//*
//* History: 9/12/01 SMT Created.
//*
//**********************************************************************
******
var URLoader_Works = (Version.NS(6) || Version.IE(5));
//**********************************************************************
******
//* Object: URLoader
//*
//* Properties: Frame - IFRAME Element
//* OnLoad - OnLoad Callback Function
//* Timeout - setTimeout() ID
//*
//* Methods: Get - Load URL
//* Clear - Clear IFRAME
//**********************************************************************
******
var URLoader = new Object();
//**********************************************************************
******
//* Method: URLoader.Get
//*
//* Parameters: URL - URL to Retrieve
//* OnLoad - OnLoad Callback Function
//*
//* Description: Builds a hidden IFRAME, if necessary, and loads 'URL'
into it.
//* When the URL is fully loaded, 'OnLoad' is called with
the
//* IFRAME.document.documentElement property.
//**********************************************************************
*******
URLoader.Get = function(URL,OnLoad)
{
if (!URLoader_Works)
{
alert('URLoader does not work in this browser.');
return;
}
//*---------------------------------------------------------*
//* Create the invisible IFRAME at the end of the document. *
//*---------------------------------------------------------*
if (!this.Frame)
{
f = document.createElement('IFRAME');
f.style.visibility = 'hidden';
document.body.appendChild(f);
this.Frame = window.frames[window.length-1];
}
//*--------------------------------------------------------------*
//* Save the OnLoad method, set the Timeout to check for load *
//* in MSIE, specify the onload method for NS, and load the URL. *
//*--------------------------------------------------------------*
this.OnLoad = OnLoad;
this.Timeout = setTimeout("URLoader_Timeout()",100);
this.Frame.onload = URLoader_OnLoad;
this.Frame.location = URL;
}
//**********************************************************************
*******
//* Handler: URLoader_OnLoad
//*
//* Parameters: none
//*
//* Description: Handles the onload event for the IFRAME window. The
Timeout
//* is cleared and the OnLoad Callback is called with the
//* IFRAME.document.documentElement property.
//*
//* This works in Netscape but not IE. In IE, this
handler is
//* called by the Timeout handler.
//*
//* In NN, the IFRAME document is cleared otherwise the
onload
//* event will not be triggered if the same document is
loaded
//* again.
//**********************************************************************
*******
function URLoader_OnLoad()
{
clearTimeout(URLoader.Timeout);
DocElem = URLoader.Frame.document.documentElement;
if (Version.NS())
URLoader.Frame.location = 'about:blank';
URLoader.OnLoad(DocElem);
}
//**********************************************************************
*******
//* Handler: URLoader_Timeout
//*
//* Parameters: none
//*
//* Description: Handles the Timeout event for the URLoader object.
This gives
//* NN the opportunity to load the URL and trigger the
onload
//* event. For IE, the document.readyState property is
checked
//* for "complete" and the onload event handler is called.
//**********************************************************************
*******
function URLoader_Timeout()
{
if (Version.IE() && URLoader.Frame.document.readyState == "complete")
URLoader_OnLoad();
else
URLoader.Timeout = setTimeout("URLoader_Timeout()",100);
}
-------------------------------------
If this helps or you have any suggestions to this, let me know. If you
modify this to work in other browsers, I would love to be informed. I
have no current need for other browsers but may in the future.
Cheers!
Steve Thames
Softlife Consulting, Inc.
http://www.webs4soft.com/Links4.htm
http://hotelsinindia.webs4soft.com/hotels-in-delhi.htm
http://indiatravel.webs4soft.com/Resources.htm
http://indianmovies.webs4soft.com/Kuch-Kuch-Hota-Hai.htm
http://real-estate.webs4soft.com/property-tips.htm
http://foodhealthcaretips.webs4soft.com/Resources.htm
http://www.websitecompanyindia.com/seo-Links.htm
http://www.websitecompanyindia.com/seo-Links.htm
http://indianjewelry.websitecompanyindia.com/dimond-ring.htm
http://www.bestindiaeducation.com/Link-Exchange.htm
http://bestjobconsultant.bestindiaeducation.com/PARTNERS.htm
http://eloctronicandmobilestore.bestindiaeducation.com/mobile-links.htm
http://easyloanservice.bestindiaeducation.com/Home-Insurance-Links.htm
http://www.rajhealthcenter.com/Cosmetic-Surgery.htm
http://creativebusinessgroup.rajhealthcenter.com/Business-Links.htm
http://onlinefreeinternetgames.rajhealthcenter.com/Games-Links.htm
http://top-beauty-tips.rajhealthcenter.com/Beauty-Links.htm
http://www.indiatourpoint.com/Travel-Links.htm
http://four-wheeler-buy-tips.indiatourpoint.com/Auto-Links.htm
http://watch-online-free-cricket-match.indiatourpoint.com/Sports-Links.htm
http://directory.indiatourpoint.com/
http://www.bestlifeindia.com/Resources1.htm
http://directory.bestlifeindia.com/
http://freeorkutscrapandsms.bestlifeindia.com/SMS-Links.htm
http://onlinegiftshop.bestlifeindia.com/Gift-Links.htm
http://www.freemusicpoint.com/Music-Links.htm
http://love-dating.freemusicpoint.com
http://online-art-presentation.freemusicpoint.com/
http://onlinefurnitureshop.freemusicpoint.com/