views:

318

answers:

3

How to prompt browser to display open/save dialog box using jquery?

+1  A: 

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

Sarfraz
@sarfraz any other possibilty to do it in asp.net?
bala3569
@bala3569: asp.net is server-side language, it can not interact directly with the browsers. So I am sorry there is no chance in that either.
Sarfraz
A: 
$(document).bind('keydown', function(e){
  switch(e.which){
    case 83:{

      if(e.ctrlKey){
          var prompt = 0;//confirm('save?');

          if(!prompt){
            e.preventDefault();
            e.stopPropagation();
            return(false);
          }
      }
    }
  }
});

This code will block the ctrl+s shortcut. I didn't figure out why confirm() and alert() destroy this mechanism. But you should be able to create a custom confirmation dialog!

Should work.

Kind Regards

--Andy

jAndy
A: 

What I've done in situations such as this is open an invisible iFrame on the page using javascript, which opens a page with the apprepriate HTTP headers:

Content-Disposition: attachment; filename=genome.jpeg;

naturally change "genome.jpg" to the appropriate default filename.

Jared Forsyth