Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    JavaScript


On Fly Addition Of An Onload Event To An Iframe Document

Talking about a js script which changes an iframe src through a "ref_to
iframe.setAttribute("src", document_path);", I would like to launch a
check() fct when this new document is loaded.

Of course, knowing, I don't want (and can't n some cases where document
is generated by a cgi script) to edit every possible document which is
potentially loadable in the iframe.

In fact, I've through about the idea to on fly add an "onload='check
()'" to every document, but don't know how to do that :-(

Maybe using attachEvent or something arounnd this : I don't know. Of
course, I wish a solution working in the majors browsers.

View 7 Replies (Posted: March 12th, 2006)

Sponsored Links:

Related Forum Messages For JavaScript category:
Jquery :: Trigger Iframe Onload Event When Doing An Ajax Replacement On Content Within The Iframe
I have a view with a credit card payment form hosted on Domain A. Domain B has a seperate website with an iframe to the credit card form on domain A. The form on domain A uses an ajax form like this:

<% using (Ajax.BeginForm("CreditCard", "Framed", new { id = Model.SID },
new AjaxOptions()
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "credit-card-wrapper",
LoadingElementId = "loading-pane"

Then on domain b, I am using a custom jquery plugin to manage my iframe by allowing external events to change the src of the iframe. The usage looks like this


Which causes the iframe to change it's src to the credit card page. I also have attached an onload to the iframe like this:


Posted: Jan 19 11 at 15:01

View 1 Replies!   View Related
Jquery :: Using Document.ready() On <img Onload> Event?
I have the following need: I want to call a js each time an image is loaded on the page but
I also need that the DOM of the page is completed loaded before the js runs.I wrote the following 'dummy' example and I would like to know if it can be considered correct or not.It seems to work but, since jquery says: "The .ready() method is generally incompatible with the attribute", I would like someone to tell me: "yes, you can do that".



Posted: Oct 27 11 at 12:50

View 3 Replies!   View Related
Onload Event With Iframe?
I've got a page, if the page gets selected I want the pdf document to load in a frame. Originally the code had a button where if you clicked it it opened the pdf '', I tried to change that so that if the page loads it must open the pdf but no luck.

<head><title>Body onload example</title>


Posted: Jun 20 at 13:44

View 1 Replies!   View Related
Jquery :: Can't Bind Iframe's Onload Event
JSFiddle's link

Like jquery can't bind file-input's onchange event??

EDIT:I cant understand why the jquery cant bind the onload event in time(like ThiefMaster said). Onload is such different from other events?

Posted: Oct 26 at 8:02

View 2 Replies!   View Related
OnLoad Event In Iframe Not Firing In IE8 After Reload?
I have an iframe on my page and I am trying to reload the contents. In all other browsers this is achieved by simply doing:


However, this does not work in IE (tested in 9 and 8) and I found that I can get it to reload by cloning the iframes container, adding the clone to the page and removing the original iframe as shown below:

var pe = $(window.parent.frames['myFrame'].frameElement.parentElement);
clonedPe = pe.clone();

The problem that I have is that on the original iframe I had some code added to the onload event but this is not fired on the load of the cloned iframe.My question there a better way of reloading the iframe in IE - OR - how can I get the onload event to fire on reload!?!

Posted: Dec 14 11 at 17:17

View 2 Replies!   View Related
Adding An Onload Event To Body Of IFrame Does Not Work?
I am trying to dynamically add an iFrame to a page and insert a 'script' tag to the 'head' tag of the iFrame. I am trying to do this through adding an onload event to the body of the iFrame so that the loading javascript i'm appending doesn't slow down the speed of the page. But it doesn't seem to work (or actually add the onload event) in Chrome (or iPhone Safari or Android emulator).

I have successfully created the iFrame with javascript and using the code below trying to add the script tag to the iFrame head:

var iframeTag = document.getElementById('myIframe');
doc =;
doc.write("<body onload='var d=document;var h=d.getElementsByTagName('head')[0];var sc=h.appendChild(d.createElement('script'));sc.language='javascript';sc.src='iframe.js';'");

Posted: Jan 6 at 17:26

View 2 Replies!   View Related
Dynamically Create An Iframe And Attach Onload Event To It?
I have created a iframe dynamicaly and added a src attribute to it. Then i have appended this iframe to body of the page. Know i want to attach an onload event to iframe to read the iframe content.

frame = document.createElement('iframe');


Posted: May 31 11 at 6:24

View 2 Replies!   View Related
Hide Elements In IFrame Before OnLoad Event Finished?
I want to hide elements of an website loaded in an iFrame. The script and the site can take a while so it is requested that the iFrame content is only shown after it has been modified. I use an onload event to execute the script which hides the elements. I have access to the iFrame content (it's on the same domain, but not the same server / network).

function frameLoaded() {
sleep(3000); //simulating the time the script needs
var leftDiv = window.frames.testFrame.document.getElementById("leftcol"); = "none";

The simple sleep function:
function sleep(milliSeconds){
var startTime = new Date().getTime(); // get the current time
while (new Date().getTime() < startTime + milliSeconds); // hog cpu

When the Website with the iFrame is loaded for the first time a scroll-bar and some styled elements are shown, but no content text: [URL]
When the script is done the page is displayed as it should be (the azure colored div becomes hidden): [URL]
While the script is working there shouldn't be displayed anything. Either an empty iframe or the whole website waiting till the onload is finished would be sufficient.

Posted: Jun 6 11 at 11:14

View 1 Replies!   View Related
Back Button Causes IFrame To Delay Window.onLoad Event?
I serve ads through an iFrame. The ad network's servers are much slower than mine, so I asyncronously load the iFrame on the window.onload event.

// (using Prototype library)
Event.observe(window, 'load', function() {
$('ad').writeAttribute('src', '/ad.html');
// other initialization here

A problem occurs when you enter the site via the browser's back button. Unexpectedly, the ad iFrame attempts to load immediately (before the load listener above sets the 'src' attribute), delaying the load event for a few seconds. During these few seconds, the site is unusable because I do a bunch of initialization in window.onload.

As far as I know, this only happens in Firefox. How do I prevent this blocking load?

Posted: Dec 28 10 at 23:24

View 4 Replies!   View Related
JQuery :: OnLoad Event Not Working With Dynamically Loaded IFrame
My script loads an iframe when the user clicks a button. I want to call another function after the iframe loads, but it's not working. The iframe does load normally, but the .load() event never gets called after the iframe finishes loading. The iframe contains content from the same website (no external content). The strange thing is that I'm using the same technique described below at a few other points in my code and it works perfectly.

Here's the relevant code:
$('#myIframe').load(function () {
alert('iframe loaded');
$('#someButton').live('click', function () {
$('body').append($('<iframe id="myIframe" src="[URL]" width="100%"></iframe>'));

Posted: Nov 22 11 at 20:21

View 4 Replies!   View Related
Window.onload Vs Body.onload And Document.onready / Difference Between These?
What is the difference between window.onload, document.onready and body.onload

Posted: Aug 13 10 at 5:04

View 1 Replies!   View Related
Why Does Window.onload Work While Document.onload Doesn't
why the following page doesn't trigger an alert when it loads? If I use window.onload instead of document.onload it works. Why is there this difference?


Posted: Feb 27 11 at 20:16

View 3 Replies!   View Related
JQuery :: Altering Onload Event After Body Tag Is Printed - .ready() In Body Of Document?
I have a tabbed page I inherited that works through a number of queries and the results determine what tabs are printed.I want to implement some logic in PHP that will cause one tab or another to be the tab with focus when page load is completed.Is it good practice to add a call to jQuery's .ready() at the closing body tag of the document?

Posted: Jun 25 11 at 20:37

View 2 Replies!   View Related
Fire "onload" Event On Document In IE?
I am currently developing Unit Tests for a Javascript method that detects the readiness of the document. This code is already at framework level, so avoid mentions of this being already implemented in jQuery or another library.

I have successfully simulated the 'readystatechange' change event with the following code:

var event;
event = document.createEventObject();
event.type = 'readystatechange';

I failed to do the same for the 'load' event. The following code results in an invalid argument error in IE7, thrown by the call to fireEvent on the last line:

event = document.createEventObject();
event.type = 'load';

Has anyone done this, or failed to do this before? I am also interested in any suggestion to fire the event in a different way.

Edit: following the suggestion by Crescent Fresh, I changed my code to:

event = document.createEventObject();
event.type = 'load';

There is no more error, but the listener for 'onload' does not fire. Here is how I configured it:


Posted: Dec 9 09 at 16:00

View 3 Replies!   View Related
JQuery :: Trigger Event From Within IFrame On Parent Document?
Is there any reason why this is not working:

Parent document

$(document).ready(function($) {
if( $(this).parent().find('iframe')[0] )[code]....

Posted: Feb 18 11 at 21:26

View 2 Replies!   View Related
Frameset Onload Event Get Called When Each Of The Frames Has An Onload?
I'm having a hard time figuring out why the onload event is not being
called for the frameset window in the following simple example. It is
being called for each of the component frames. Code:

Posted: July 23rd, 2005

View 5 Replies!   View Related
Detect ,on Load Of The Html Document, Whether The Body Of The Iframe Document Is Ready To Be Displayed?
Suppose a HTML document has a iframe.Using javascript,I want to detect ,on load of the html document, whether the body of the iframe document is ready to be displayed.I want to be able to overwrite the the body contents (before it actullay loads) of the iframe.say if ,HTML doc is


Posted: Sep 7 09 at 5:52

View 1 Replies!   View Related
Why It Not Work In Document.onload?
window.onload= function(){
var a = document.getElementById('a');[code]....

Why the first script not working ?. Chrome : Uncaught ReferenceError: b is not defined

Posted: Aug 12 10 at 13:21

View 5 Replies!   View Related
Detect ,on Load Of The Html Document, Whether The Body Of The Iframe Document?
Suppose a HTML document has a iframe. Using javascript,I want to detect ,on load of the html document, whether the body of the iframe document is ready to be displayed.I want to be able to overwrite the the body contents (before it actullay loads) of the iframe.can I do it with jquery? say if ,HTML doc is

<html><head></head><body><iframe id="ifrmId" src="" ></iframe></body></html>

Posted: Sep 6, 2009

View 1 Replies!   View Related
Document.body.onload Not Working?
I have this test code for saving panel state using cookies:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


Posted: 06-26-2011, 11:15 AM

View 2 Replies!   View Related
Window.onload Vs Document.ready?
what is the difference between window.onload and document.ready.

Posted: Sep 13 10 at 6:24

View 2 Replies!   View Related
JQuery :: Using Window.onload Instead Of Document.ready
Ive been advised to use "window.onload" instead of "document.ready" and im having problems implementing it, im sure its a syntax error.

here is my original code

var chart;
$(document).ready(function() {

and i want to change it to onload, and im trying to get this to work
var chart;

$(window).onload(function() {

what is the proper syntax for using window.onload with jquery?

Posted: 27-Apr-2011

View 1 Replies!   View Related
Onload - Detect If Document Has Loaded (IE 7/Firefox 3)?
I want to call a function after a document loads, but the document may or may not have finished loading yet. If it did load, then I can just call the function. If it did NOT load, then I can attach an event listener. I can't add an eventlistener after onload has already fired since it won't get called. So how can I check if the document has loaded? I tried the code below but it doesn't entirely work.

var body = document.getElementsByTagName('BODY')[0];
if(body && body.readyState == 'loaded') {


Posted: Jun 11 09 at 0:14

View 7 Replies!   View Related
Use OnLoad To Change The Color Of A Word Within Document?
I have a simple html document that is dynamically created. It comes to me like this:

432 (Locked) (Disabled) <br />
545 (Unlocked) (Enabled) <br />
756 (Unlocked) (Disabled) <br />

The actual list is much longer and varies in length. What I am attempting to do is when a user opens the page, if a line contains Locked or Disabled, change the color of those words (or the whole line that contains them) to red.

Posted: 10-03-2010, 05:03 PM

View 7 Replies!   View Related
Copyright 2005-08, All rights reserved