admin管理员组

文章数量:1417442

How can I return an Open/Save dialog box to a PDF file on the server using only javascript?

I don't want the current pages location to change, however. Do I need to trigger an Iframe?

How can I return an Open/Save dialog box to a PDF file on the server using only javascript?

I don't want the current pages location to change, however. Do I need to trigger an Iframe?

Share Improve this question asked Aug 25, 2010 at 21:12 Scott KlarenbachScott Klarenbach 38.8k16 gold badges63 silver badges92 bronze badges 4
  • The only thing I can make of that is an illogical thing to do, could you explain your question in some more detail? – Jasper Commented Aug 25, 2010 at 21:15
  • I've got a one page application w/ plex UI via ExtJS. Currently reports are firing by opening up another tab in the browser. Instead, I want to fire an Open/Save dialog via javascript without opening a new tab, and without changing the location of the current tab. I've seen it done before, but can't find the code. – Scott Klarenbach Commented Aug 25, 2010 at 21:17
  • Why not simply have the webpage download the file, and let the browser handle popping up the "Open? Save?" dialog? – rlb.usa Commented Aug 25, 2010 at 21:20
  • I don't want the page to change. It's not a webpage, but an application that is loaded into the current url and maintained by javascript. – Scott Klarenbach Commented Aug 25, 2010 at 21:22
Add a ment  | 

2 Answers 2

Reset to default 2

You can open a file with the window.open mand. The prompt would depend on the user's settings as to what the default action should be.

<a href="#" onclick="window.open('http://linktoPDF', 'NewWin');">link</a>

Yeah, you'd have to use an iframe for that. You could use the style visible:false; or maybe set the height and width to 1px, but I don't know if display:none; would work. Know that for some browsers, and iframe adds to the history, but it sounds like that isn't a problem.

本文标签: open pdf file from javascriptStack Overflow