tags:

views:

200

answers:

5

Jquery:

Is there a way to catch the event that is fired when the browser opens the Open/ Save as dialog box? Open/Save dialog example

I need to do something when the dialog is shown.

Kind regards

Massimo

A: 

As far as I know, there is no way to do that.

Jan Hančič
A: 

A i know there is no particular way to detect when this window appears. Try to add click handler on the download button/icon. Or as i solved this on my project - i added async logic. when document was generated, i passed 'succes' to client, and then JS code made some logic i needed.

Konoplianko
I solved in a similar way.10x a lotMax
Massimo Ugues
+1  A: 

Not that I am aware.

I'm guessing that this will be opened when you click some item on the page. You best bet is to capture that event.

Given your anchor:

<a id="MyLink" href="MyDoc.doc">

A simple click handkler will intercept this event, before the above box pops up

$(document).ready(function(){
    $("#MyLink").click(function() {
        alert($(this).length);
    });
});
James Wiseman
A: 

Is it always the same file type that you are checking for? If so, you could do something like

$("a").click(function(e){
   var extension = $(this).attr("href").substr($(this).attr("src").lastIndexOf("."));
   if ((extension && /^(zip|vbd)$/.test(extension))){
      alert("Hi now you can do whatever you needed to do!");
   }
});

Note no e.preventDefault(), since you still want the prompt to come up I am presuming?

File extension check snippet

neatlysliced
It' always the same file extension (a pdf file) but the file is dinamically generated, and the href is initialized with the serverside controller that creates the file.I found a work around since ie6 gots a strange behaviour with the jQuery submit() function.If the function where is called the $("myForm").submit() runs and completes its execution the submit is aborted by the browser.Asap I will post a test case on jQuery forum.Thanks a lot Max
Massimo Ugues
+1  A: 

Not possible. The browser handles this specifically so that web hackers can't force you to download a virus, which would be much easier for them if it happened in javascript.

Matrym