javascript 从javascript打开pdf文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3570245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 01:33:11  来源:igfitidea点击:

open pdf file from javascript?

javascriptpdfmime

提问by Scott Klarenbach

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

如何仅使用 javascript 将打开/保存对话框返回到服务器上的 PDF 文件?

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

但是,我不希望更改当前页面的位置。我需要触发 Iframe 吗?

回答by Dustin Laine

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

您可以使用该window.open命令打开文件。提示将取决于用户关于默认操作应该是什么的设置。

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

回答by palswim

Yeah, you'd have to use an iframe for that. You could use the style visible:false;or maybe set the heightand widthto 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.

是的,您必须为此使用 iframe。您可以使用样式visible:false;或将heightand设置width1px,但我不知道是否display:none;可行。知道对于某些浏览器,iframe 会添加到历史记录中,但听起来这不是问题。