faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

54 of 86 people (63%) answered Yes
Recently 6 of 10 people (60%) answered Yes

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?

Dec 26th, 2008 21:42
Rockys rainwal, Raj Aryan, John Chena, Steve Thames, Ian Grant, http://goatravelsguide.blogspot.com/


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
[email protected]
------------------------------------------------------------------------
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!
http://www.jaipurtravelguide.com/
http://www.jaipurtravels.com/
http://www.jaipurjaipur.com/
http://www.jaipurtourismguide.com/
http://www.rajasthantravelsguide.com/
http://www.rajasthantravelguide.co.in/
http://www.travelpackagerajasthan.com/
http://www.namaskarindiatravels.com/
http://www.indianhotelsindia.com/
http://www.travelpackageindia.com/
http://www.navyatravels.com/
http://www.hillstationindiatour.com/
http://www.wildlifeindiatravel.com/ 
http://www.pushkartravels.com/
http://www.udaipurtravels.com/
http://www.agratravels.com/
http://indiantravelguide.co.in/
http://www.traveltoindia.biz/
http://www.info4india.com/
http://www.indiantravelsguide.com/
http://www.indiantravelguideindia.com/
http://rajasthantravelguide.wordpress.com/
http://attractioninjaipur.blogspot.com/
http://jaipurtravelsguide.blogspot.com/
http://hoteles-en-la-india.blogspot.com/
http://jaipurguiadeviajes.blogspot.com/
http://jaipurrajasthanindia.blogspot.com/
http://travelguiderajasthan.blogspot.com/
http://travelguiderajasthan.blogspot.com/
http://wildlifeindiatravel.blogspot.com/
http://indiantravelguideindia.blogspot.com/
http://indianhotelsindia.blogspot.com/
http://rajasthantravelsguide.blogspot.com/
http://pushkartravels.blogspot.com/
http://indiatravelsguide.blogspot.com/
http://goaguidedevoyage.blogspot.com/
http://goatravelsguide.blogspot.com/
http://indiaguadeviajes.blogspot.com/
http://htelseninde.blogspot.com/
http://indienguidedevoyage.blogspot.com/
http://indianhillstationsindiatravel.blogspot.com/
http://jaipurtravelguiderajasthan.blogspot.com/
http://hillstationinindia.blogspot.com/
http://jaipurcarrentals.blogspot.com/
http://indiabudgettourtravelpackage.blogspot.com/
http://romanticrajasthanhoneymoontour.blogspot.com/
http://indianadventuretourpackages.blogspot.com/
http://rajasthantraintourpackage.blogspot.com/
http://jaipurinformationguide.blogspot.com/
http://rajasthanculturaltourpackages.blogspot.com/
http://uttaranchaltourpackages.blogspot.com/
http://luxurytourspackages.blogspot.com/
http://indiahimalayatourtravelpackages.blogspot.com/
http://eastindiatravelpackages.blogspot.com/
http://indiahillstationstravelpackages.blogspot.com/
http://indiatravelpackages.blogspot.com/
http://westindiatourpackages.blogspot.com/
http://lehladakhtourpackages.blogspot.com/
http://indiabudgettourtravelpackage.blogspot.com/
http://romanticrajasthanhoneymoontour.blogspot.com/
http://worldtravelsguide.blogspot.com/
http://jaipursilverjewellery.com/
http://www.jaipurhandicrafts.com/