views:

46

answers:

2

Hi all,

Basically, I would like to wait for the IE save dialog box to open up, and then run the next line of JavaScript.

Something like:

`window.open(URL,"_self",...);`

window.alert("save dialog started");

Can this be done? Thanks

Grae

I came up with this:

              var iframe = document.getElementById("dFrameID");
              if(iframe.readyState=='complete')
                 window.close();

else wait and call this again.

Seems to work fine.

A: 

I haven't tested this, but you may be able to use setTimeout(...) to get there. I have used it (only in IE) to wait until a print preview dialog had been closed.

The trick would be to wait in a loop (say five times) with enough time between those five loops to guarantee that the save dialog would have appeared. Once the dialog appears, all javascript processing should freeze. Then, when the box is closed, the javascript would start up again, and your setTimeout handler would execute.

Again, I have no idea whether this will actually work, and it would probably be different based on the browser you're using. It is also complicated by the likelyhood that your download window and alert window would be separate.

John Fisher
...but there is the use-case of the user that chooses Cancel...
michael
@Michael. Then hopefully he could detect that the page had closed (because of the cancel) and respond appropriately.
John Fisher
@John - Maybe I mis-understand but the Cancel will only close the Dialog window, not the Page. The setTimeout will still trigger an alert with incorrect information.
michael
@Michael - This is where browser-specific things come into play. I've definitely seen browsers open a new blank page to download something, and the page only shows long enough to download or cancel. (So that scenario has a page close along with the cancel.)
John Fisher
@John - I believe that is (or can be) determined by Preference. Regardless I haven;t seen it consistently in IE so its probably not a robust solution. Could be wrong though.
michael
@John What sort of test do you think I should use. The timeout bit works ok, but what is the condition I should check for?
Grae
I figured out you have to use iframe.readyState
Grae
+1  A: 

Javascript and the browser do not interact on this level.

michael
Tell me about it! lol
Grae