473,804 Members | 3,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Iframe IE onload problem

1 New Member
Look at the following code:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. </head>
  5. <body>
  6.  
  7. <iframe id="olaf" name="olaf" onload="alert('no');"></iframe><br>
  8. <input type="submit" onclick="document.getElementById('olaf').src = 'phpinfo.php'" value="Test">
  9.  
  10. </body>
  11.  
  12. <script language="javascript">
  13. var obj = document.getElementById('olaf');
  14. obj.onload = function() { alert('yes'); }
  15. </script>
  16.  
  17. </html>
The "obj.onload =" contruct should override the first onload statement. In Firefox it works fine and when I click the button a "yes" message is shown. But in Internet Explorer the "no" message is shown. My problem is that I need to set the function (anonmymous) that should be called by the brower when iframe.onload and I can't get this to workin in IE. Can anyone help?

Thanks!
/Niels
Jul 9 '06 #1
8 64003
bagrbagr
1 New Member
I have the same problem with changing onload event of iframe in internet explorer. Instead of:

Expand|Select|Wrap|Line Numbers
  1. <iframe id="ifrm" onload="foo1();"></iframe>
and script:

Expand|Select|Wrap|Line Numbers
  1. getElementById("ifrm").onload = foo2
;

I used:

Expand|Select|Wrap|Line Numbers
  1. <span="ifrm_wrap"><iframe id="ifrm" onload="foo1();"></iframe></span>
and script:

Expand|Select|Wrap|Line Numbers
  1. getElementById("ifrm_wrap").innerHTML = '<iframe id="ifrm" onload="foo2();"></iframe>';
Not very nice, but works.
Feb 28 '07 #2
jianwu
1 New Member
I face the same problem. This looks like a stupid IE bug, I wasted hours of time struggling on this issue.

I noticed you can't get or set the onload event for iframe in I.E. When you get, you always get null even you put the onload attribute in the tag. When you set it, you can get what you set, seems it's ok. But the I.E will only call the one you specified in the IFRAME tag. Just ignore what you set. That's strange.

I finally find a walkaround. In the IFRAME tag, i hard code onload to call another function. Then I can set the value of another function.

Expand|Select|Wrap|Line Numbers
  1. <iframe style="display:none" id='f1' onload="this.onload_1();" />
  2.  
Expand|Select|Wrap|Line Numbers
  1. document.getElementById(f1).onload_1 = function(){alert('test');}
That works.
Dec 8 '07 #3
JeremyMiller
69 New Member
I know this is an old thread, but the first I encountered when searching for an answer, so I thought I'd chime in. To do it, you need to attach the event. I have event attachment wrapped in a function, but this should help:

Expand|Select|Wrap|Line Numbers
  1. eventPush(document.getElementById('frame_id'),'load',function () {myFrameOnloadFunction();});
  2.  
  3. function eventPush(obj, event, handler) {
  4.   if (obj.addEventListener) {
  5.     obj.addEventListener(event, handler, false);
  6.   } else if (obj.attachEvent) {
  7.     obj.attachEvent('on'+event, handler);
  8.   }
  9. }
  10.  
Oct 26 '08 #4
adamt326
1 New Member
I was having this same problem. My code worked in every browser but IE. Here is my solution:

My original code was:

<iframe id="id" name="id" onload="functio n_name();" scrolling="auto " frameborder="1" src="example.as p"</iframe>
The working code is:

<iframe id="id" name="id" onload="return function_name() ;" scrolling="auto " frameborder="1" src="example.as p"</iframe>
I didn't think I was passing anything because my JavaScript doesn't have a return functionality to it but if it works..it works. This still work fine in Chrome and Firefox.
Aug 4 '09 #5
splarryl
1 New Member
Thanks so much for all your help. I'm no expert in this "stuff" but my function calls to objects in an IFRAME did not work on IE, did everywhere else. Some of the techniques suggested here did not seem to work, others were a bit too complicated for me to follow.

A litte extra searching turned up this link:
http://www.dyn-web.com/tutorials/iframes/

And this interesting info:
(accessing IFRAME content)

// IE5.5+ windows
1) document.getEle mentById(iframe Id).contentWind ow
2) document.getEle mentById(iframe Id).contentWind ow.document
or,

// DOM
3) document.getEle mentById(iframe Id).contentDocu ment

"3)" is what I began with, n/g in IE
"1)" also n/g
"2)" worked in IE, Firefox & Chrome

Go figure.
Jan 9 '10 #6
WouterH
1 New Member
I came accross this thread when googling, I had the exact same problem. All the above solutions did not work for my case. I came up with a solution myself, which might be of help to others.

I used

window.onload = document.getEle mentById('frame id').setAttribu te('onload', 'whateverfuncti onyouwant();');

as far as I can see this works for all browsers I tested on. Tested on Safari, Firefox, IE and Opera

In my case I had a dynamicly created iframe through javascript. I did this to have the onload events execute before the content of the iframe is fully loaded. The content of the iframe is from an external domain, so sometimes the content loads quite slow and I did not want my visitors to have to wait for that before they can acces the page.

This solution helps with a problem like in:

Expand|Select|Wrap|Line Numbers
  1. newFrame = document.createElement('iframe');
  2. newFrame.src = 'http://www.google.nl';
  3. newFrame.style.width = '600px';
  4. newFrame.style.height = '2500px';
  5. newFrame.setAttribute('onload', 'scroll(0,0)');
  6. document.getElementsByTagName('body')[0].appendChild(newFrame);
On the above example the page will return to the top of the document, whenever the iframe loads in a new document. When someone would have made a query through the iframe and hits next page, the document would automaticly go back to the top.

Hope this helps atleast someone.

Kind regards,

Wouter
Sep 8 '10 #7
rbuczynski
10 New Member
I tried every solution posted above for my problem, and none of them worked. In my case, I have a form containing a file for upload whose target is pointed towards a static IFRAME element.

The FORM:
Expand|Select|Wrap|Line Numbers
  1. <form action="upload.php" method="post" enctype="multipart/form-data" target="myIframe">
The IFRAME:
Expand|Select|Wrap|Line Numbers
  1. <iframe name="myIframe" id="myIframe" src=""></iframe>
When the form submits, the file is handled by a PHP upload script. Now, in my case, I needed to have the contents of the uploaded file (an HTML page) output to the IFRAME window, like so:

Expand|Select|Wrap|Line Numbers
  1. <?php echo file_get_contents($_FILES['myFile']['tmp_name']); ?>
Additionally, I needed a callback to let my controlling script in the parent window know when the IFRAME's content has loaded. As you all know, this was easy enough in a Mozilla browser. In fact, I could communicate with the parent window using at least 5 different methods! However, not a single one worked for IE.

Then some of your suggestions got me thinking about this ONLOAD attribute for IFRAMEs. Even though none of the solutions worked, I did some research. Some people have said that even though the specification allows for the ONLOAD attribute in an IFRAME element, it just doesn't work (a bug in IE?!).

Finally, I stumbled upon this page:

http://msdn.microsoft.com/en-us/libr...s.85%29.aspx#4

This commenter shows his work using Microsoft's exclusive JScript coding. It was then that the solution was quickened to me! Here is his sample code:

Expand|Select|Wrap|Line Numbers
  1. <script for="window" event="onload" language="JScript">
  2.   window.status = "Page is loaded!";
  3. </script>
This effectively binds an ONLOAD event handler to the IFRAME element! But since the above snippet is ignored by FireFox, I simply write combined code to perform my cross-browser compatible callback.

My PHP upload script, then, looks like this:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo file_get_contents($_FILES['source-file']['tmp_name']);
  3.  
  4. <script language="javascript">
  5. // For Mozilla
  6. parent.window.myIframe.setAttribute('onload','myCallbackFunc();');
  7. </script>
  8.  
  9. <script for="window" event="onload" language="jscript">
  10. // For Microsoft
  11. parent.window.myCallbackFunc();
  12. </script>
  13. ?>
I hope this helps!
Feb 7 '11 #8
Supun Kavinda
1 New Member
The problem can be Iframe loading before the script is executed. This can be prevented by adding the Iframe using Javascript.


Expand|Select|Wrap|Line Numbers
  1. var iframe = document.createElement("iframe");
  2. document.body.appendChild(iframe);
  3.  
Nov 6 '19 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
7444
by: saayan | last post by:
Hi, I have a php generated HTML page, which has a javascript call in the body tag: <body onunload="exitPage()" onload="setWidth()" onresize="setWidth()"> In certain cases, there can be an iframe in the page: <iframe src="/secure/download.php?dl_file=test.txt" style="display: none" />
4
7622
by: Thomas | last post by:
Hi there, I have an iframe which is editable (designMode = "on") and want to resize it dynamically as the content grows (e.g. more lines of text is in there) and there the struggle starts. I fill the iframe with content (<body> tag and so on and also insert a <div> tag, inbetween is the content that should be modified). Now if the event "overflow" or "underflow" is triggered the iframe
5
2261
by: Grzesiek | last post by:
Hi! I have created page which contains some menu buttons and <iframe> with sub-page. Each menu action on the master web site should change content of iframe (by changing src attribute). But how to detect when user has opened subpage not in master's <iframe> ? Is it possible to obtain reference to master's page from sub-page ? When I'm trying to do this using Page.Parent I get null exception :( Here's a piece of code //master.aspx
0
5894
by: dimepiece18 | last post by:
On our Intranet homepage, I have a layer with an iframe contained in it. The iframe is linked to an html document that is stored in our Content Library system. You have to be authorized to view the documents in Content Library. The problem I'm having is that when you launch the Intranet site, the SSO login screen appears, but it looks like the iframe is trying to launch the html file before the homepage loads. So after you log in, the iframe...
1
10388
by: Dave | last post by:
Usual apologies if this is old territory. I'm resizing a bunch of iframes on a page to the height of their contained documents. Some of the contained documents contain IMG tags. On IE this doesn't cause a problem and the resize works correctly. On Firefox, if an image extends below the last line of text in the document, that bit gets chopped off. In other words, the returned document height doesn't allow for the image. My code for...
7
9638
by: Tom Cole | last post by:
IFrames have been used by years for people to accomplish many of the tasks the XMLHttpRequest does for them now...I unfortunately am late in the game and XMLHttpRequest was already out there by the time I got serious about using Javascript for more than just rollover images... I now would like to learn about the concept for the purposes of creating Ajax-like requests across domains. I felt like I had the basic concept down, but am...
1
5287
by: XP | last post by:
Hello Everyone, I was stuck with this really frustrating problem for sometime. Let me explain what I am trying to achieve: There is a form and an inner iframe. The form's target is set to the iframe so that when the form is submitted, the page does not get reloaded/changed ( as the iframe would be the one getting refreshed. The Iframe is set to have 0 width and height to make it look invisible ). I have a copied the html source ( at...
3
2969
by: whatever0 | last post by:
Hi, I'm fairly new to javascript and was hoping i could have a little help... I have a page containing a form and an iframe. The iframe is initially empty (src="about:blank"). The target of the form is the iframe, so when the form is submitted the iframe loads a page (which is remote and I cannot edit). What i would like to happen is that when the contents of the iframe has finished loading, the page (as in: the entire page) then...
0
9587
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.