iframe IE javascript onload problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • saayan@gmail.com

    iframe IE javascript onload problem

    Hi,
    I have a php generated HTML page, which has a javascript call in the
    body tag:

    <body onunload="exitP age()" onload="setWidt h()" onresize="setWi dth()">

    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.
    but,
    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?

    Thanks,
    Saayan

    The /secure/download.php looks like this:

    <?php

    if(!empty($_GET['dl_file']))
    {
    // 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=\"$fil ename\"");

    $path = dirname(__FILE_ _)."/../download";

    readfile("$path/$filename");
    exit();
    }
    }

    ?>

  • saayan@gmail.com

    #2
    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.

    <?php

    if(!empty($_GET['dl_file']))
    {
    if($_GET['dl_file'] == 'test.txt')
    {
    exit();
    }

    }

    ?>

    Comment

    • saayan@gmail.com

      #3
      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
      above.

      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
      setWidth
      // why need to wait until 'content' div ? Because this div is
      manipulated in setWidth()

      var minmax_SCANDELA Y= 500;

      var minmax_scanner;

      function minmax_scan() {
      if (!document.getE lementById('con tent')) return;
      window.clearInt erval(minmax_sc anner);
      setWidth();
      }

      minmax_scan();
      minmax_scanner= window.setInter val(minmax_scan , minmax_SCANDELA Y);

      Comment

      Working...