iframe IE javascript onload problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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" />

This technique has been mentioned by Chung Leong in several posts to
open a file save dialog in the browser (and load the HTML page at the
same time .. 2 HTTP requests).

The problem is:

in Firefox, all works fine, the page loads, the javascript setWidth is
called for onload, and the file dialog appears.
In IE 6, the file dialog shows, but the javascript onload event is
never triggered.

Can anyone help please. Am I missing something here? Any way to get
around this problem in IE?


The /secure/download.php looks like this:


    // check the valid files here
    // and don't accept random requests
    // potentially naughty :)

    // can read the db here for valid list
    // TODO
    // now only one file, so don't make this
    // complex

    if($_GET['dl_file'] == 'test.txt')
        header("Content-type: application/octet-stream");
        $filename = $_GET['dl_file'];
        header("Content-disposition: attachment; filename=\"$filename\"");

        $path = dirname(__FILE__)."/../download";


Re: iframe IE javascript onload problem

Observed this:
if the download.php (basically do nothing inside it) is like below,
there is no problem in both Firefox and IE. But, then of course the
file save dialog does not appear.


        if($_GET['dl_file'] == 'test.txt')



Re: iframe IE javascript onload problem

Workaround (could not have a direct fix) -

Problem - how to call the setWidth() function, even though IE is not
invoking the onload event handler, under the conditions mentioned

Solution =>

In the javascript file (which has the setWidth() function), I added the
following code (simulating the onload event handler):
(Inspiration - minmax.js written by Andrew Clover)

// Scanning. Check document every so often until it has finished
loading. Do
// nothing until the 'content' div arrives, then stop scanning and call
// why need to wait until 'content' div ? Because this div is
manipulated in setWidth()

var minmax_SCANDELAY= 500;

var minmax_scanner;

function minmax_scan() {
    if (!document.getElementById('content')) return;

minmax_scanner= window.setInterval(minmax_scan, minmax_SCANDELAY);

Site Timeline