Javascript 不会更改 PDF 或 Zoom 中的页面
Javascript won't change pages in PDF or Zoom
我正在使用 Windows 10,我的桌面上有一个名为 pdf.html
的文件。
pdf.html
的内容是。
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function goAndZoom(pageNum,zoom)
{
var pdf = document.getElementById('pdf');
pdf.data = pdf.data+'#page='+pageNum+'&zoom='+zoom;
document.body.removeChild(pdf);
document.body.appendChild(pdf);
}
</script>
</head>
<body>
<button onclick="goAndZoom(4,300);">Go to Page 4 and zoom 300%</button>
<object id="pdf" data="http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf" width="100%" height="700px" type="application/pdf">
<param name="zoom" value="100" />
</object>
</body>
</html>
我在 Chrome 中打开这个文件。当我按下按钮 "Go to page 4 and zoom 300%" 时,嵌入的 pdf 将转到第 4 页并缩放 300%。当我在 Edge 浏览器中重复这两个操作时,pdf 停留在第 1 页,而没有改变缩放比例。我与其他人共享了这个 pdf.html
文件,他们在使用 IE 11 时报告了同样的问题。
如何获得 goAndZoom()
功能以转到 PDF 中的页面并在 IE 和 Edge 中放大?
Internet Explorer 在处理 html 对象时有奇怪的行为。尝试使用相同的属性创建一个新对象。
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function goAndZoom(pageNum,zoom)
{
var pdf = document.getElementById('pdf');
var newPdf = document.createElement("object");
newPdf.type = "application/pdf";
newPdf.height = pdf.height;
newPdf.width = pdf.width;
newPdf.id = pdf.id;
newPdf.data = pdf.data+'#page='+pageNum+'&zoom='+zoom;
document.body.removeChild(pdf);
document.body.appendChild(newPdf);
}
</script>
</head>
<body>
<button onclick="goAndZoom(4,300);">Go to Page 4 and zoom 300%</button>
<object id="pdf" data="http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf" width="100%" height="700px" type="application/pdf">
<param name="zoom" value="100" />
</object>
</body>
</html>
截至 2016 年 4 月 27 日不存在解决方案
我知道我来晚了,但这就是答案...
在 IE 中,您实际上(可能)使用 Adobe Reader 通过 Reader 插件显示 PDF。如果 PDF 尚未在查看器中打开,则 PDF 打开参数会起作用,但当您将它们附加到同一来源时,它们不会起作用。 Reader 知道文件已经打开并忽略打开参数。您需要先将数据 属性 设置为空,然后使用参数返回 URL 以使其正常工作。
对于Edge...放弃。它不会解释开放参数。
我正在使用 Windows 10,我的桌面上有一个名为 pdf.html
的文件。
pdf.html
的内容是。
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function goAndZoom(pageNum,zoom)
{
var pdf = document.getElementById('pdf');
pdf.data = pdf.data+'#page='+pageNum+'&zoom='+zoom;
document.body.removeChild(pdf);
document.body.appendChild(pdf);
}
</script>
</head>
<body>
<button onclick="goAndZoom(4,300);">Go to Page 4 and zoom 300%</button>
<object id="pdf" data="http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf" width="100%" height="700px" type="application/pdf">
<param name="zoom" value="100" />
</object>
</body>
</html>
我在 Chrome 中打开这个文件。当我按下按钮 "Go to page 4 and zoom 300%" 时,嵌入的 pdf 将转到第 4 页并缩放 300%。当我在 Edge 浏览器中重复这两个操作时,pdf 停留在第 1 页,而没有改变缩放比例。我与其他人共享了这个 pdf.html
文件,他们在使用 IE 11 时报告了同样的问题。
如何获得 goAndZoom()
功能以转到 PDF 中的页面并在 IE 和 Edge 中放大?
Internet Explorer 在处理 html 对象时有奇怪的行为。尝试使用相同的属性创建一个新对象。
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function goAndZoom(pageNum,zoom)
{
var pdf = document.getElementById('pdf');
var newPdf = document.createElement("object");
newPdf.type = "application/pdf";
newPdf.height = pdf.height;
newPdf.width = pdf.width;
newPdf.id = pdf.id;
newPdf.data = pdf.data+'#page='+pageNum+'&zoom='+zoom;
document.body.removeChild(pdf);
document.body.appendChild(newPdf);
}
</script>
</head>
<body>
<button onclick="goAndZoom(4,300);">Go to Page 4 and zoom 300%</button>
<object id="pdf" data="http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf" width="100%" height="700px" type="application/pdf">
<param name="zoom" value="100" />
</object>
</body>
</html>
截至 2016 年 4 月 27 日不存在解决方案
我知道我来晚了,但这就是答案...
在 IE 中,您实际上(可能)使用 Adobe Reader 通过 Reader 插件显示 PDF。如果 PDF 尚未在查看器中打开,则 PDF 打开参数会起作用,但当您将它们附加到同一来源时,它们不会起作用。 Reader 知道文件已经打开并忽略打开参数。您需要先将数据 属性 设置为空,然后使用参数返回 URL 以使其正常工作。
对于Edge...放弃。它不会解释开放参数。