在Windows中无法打开窗口的情况下打开PDF

时间:2018-10-12 09:11:08

标签: javascript pdf

我正在使用以下代码在window.open中打开pdf,以获取pdf的动态标题。

此代码可以正常工作,但在Chrome浏览器中无法正常工作。

打开时我看到pdf的标题,但pdf未打开。

function titlepath(path,name)
{
  var prntWin = window.open();
  prntWin.document.write("<html><head><title>"+name+"</title></head><body>"
  + '<embed width="100%" height="100%" name="plugin" src="'+path+'" '
  + 'type="application/pdf" internalinstanceid="21"></body></html>');
  prntWin.document.close();
}

1 个答案:

答案 0 :(得分:1)

假定相同的协议和可能相同的来源

注意: :假设PDF也来自网站,因为您可能会从文件系统加载问题

注意: :如果服务器发送了{{3}},则可能不允许您显示它

尝试使用iFrame

function titlepath(path,name) {
  var prntWin = window.open("");
  prntWin.document.write("<html><head><title>"+name+"</title></head><body>" + 
  '<iframe width="100%" height="100%" name="plugin" src="'+path+'"></iframe></body></html>');
  prntWin.document.close();
}

或至少关闭嵌入

function titlepath(path,name) {
  var prntWin = window.open("");
  prntWin.document.write("<html><head><title>"+name+"</title></head><body>" +
  '<embed width="100%" height="100%" name="plugin" src="'+path+'"></embed>'+
  '</body></html>');
  prntWin.document.close();
}