按下按钮时,始终在给定页面上打开PDF [英] Always open a Pdf on a given page when button pressed

查看:77
本文介绍了按下按钮时,始终在给定页面上打开PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下测试代码用于询问我的问题. 第一次运行它,然后单击按钮,在第一页上打开Pdf. 这是正确的,并且适用于所有最新的浏览器.

The following test code was made for the purposes of asking my question. Running it for the first time and clicking the button, opens the Pdf on the first page. This is correct and works for all the latest browsers.

如果我随后将Pdf滚动到另一个页面并重新单击按钮,则Pdf仅在使用Google Chrome浏览器的第一页上再次打开.其他浏览器没有任何反应,页面保持不变.

If I then scroll the Pdf to another page and re-click the button, the Pdf only opens on the first page again with Google Chrome. Nothing happens in the other browsers and the page remains the same.

我的问题是,有谁知道如何使用FF和IE使Pdf返回第一页.

My question is, does anyone know how to get the Pdf to return to the first page using FF and IE.

如果有人有任何想法,我很乐意彻底改变自己的方法.

I am more than happy to completely change my approach if anyone has any ideas.

非常感谢.

<input type="button" id="getP1" value="Get Page 1" />

<div class="pdf"></div>

<script type="text/javascript">
  $(function () {
    $("#getP1").click(function () {
      var fname = "/PDFFiles/Somefile.pdf#page=1";
      $('div.pdf').replaceWith("<div class='pdf'><iframe src='" + fname + "' height='500px'></iframe></div>");
    });
  });
</script>

推荐答案

尝试在文件名后添加查询字符串参数.它应该使浏览器认为它是一个新文档,然后再次加载它.

Try to add a query string parameter after the file name. It should make the browser think that it's a new document and load it again.

<input type="button" id="getP1" value="Get Page 1" />

<div class="pdf"></div>

<script type="text/javascript">
  $(function () {
    $("#getP1").click(function () {
      var ticks = new Date().getTime();
      var fname = "/PDFFiles/Somefile.pdf#page=1";
      $('div.pdf').replaceWith("<div class='pdf'><iframe src='" + fname + "?" + ticks + "' height='500px'></iframe></div>");
    });
  });
</script>

这篇关于按下按钮时,始终在给定页面上打开PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆