javascript - 在打开窗口的情况下打开 pdf 在 Chrome 中不起作用
问题描述
我正在使用下面的代码在 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();
}
解决方案
假设相同的协议和可能相同的来源
注意:假设 PDF 也来自网站,因为您可能会遇到从文件系统加载的问题
注意:如果服务器发送x-frame-options,您可能无法显示它
尝试 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();
}
推荐阅读
- python - 以下两个输出代码片段之间可能有什么区别?
- php - 如何绕过 PHP 连接中的错误 111 MySQL?
- r - 是否有一个 R 函数可以在某个字符串之后移动数据?
- python - azure keyvault 和 azure identity 共存
- html - Namecheap DNS & Xampp Webserver - 重定向
- unit-testing - Redux saga 选择器单元测试问题
- terraform - 带有可选值的 Yamldecode
- java - 当您更改 xml 文件中的属性时,会调用哪个自定义视图的构造函数?
- php - 通过 nginx/laravel API 调用登录尝试失败
- r - 如何修复在 Shiny 中未弹出 esquisserUI 的过滤器选项?