如何在Chrome PDF查看器中更改页面?

时间:2018-04-10 15:27:31

标签: javascript html google-chrome pdf iframe

无法找到符合我在此处尝试的问题。我在我的网页上有一个嵌入式PDF,在iframe内部,我在页面上有一些按钮,它们将改变iframe的src以更改页面。 这似乎适用于IE11和firefox,因为他们使用adobe PDF查看器,但我在Chrome和Vivaldi等使用chrome pdf viewer的浏览器上遇到了问题。

这是我的代码: HTML:

<button class="pageChanger" value="http://linktomypdf.pdf#page=1">Start Of Section</button>
<button class="pageChanger" value="http://linktomypdf.pdf#page=20">Section 2</button>
<button class="pageChanger" value="http://linktomypdf.pdf#page=35">Section 3</button>
<button class="pageChanger" value="http://linktomypdf.pdf#page=45">Section 4</button>
<iframe id="iframepdf" src="http://linktomypdf.pdf#page=1" width="800" height="800"></iframe>

JS:

<script>
    jQuery(document).ready(function() {
      jQuery(".pageChanger").on('click', function() {
        jQuery("#iframepdf").attr("src", jQuery(this).val());
      });
    });
  </script>

iframe仍将使用所选HTML中的指定页面加载,但我之后更改页面的JS功能仅适用于adobe PDF查看器。 这不是在chrome PDF查看器中以编程方式更改页面的正确方法吗?

1 个答案:

答案 0 :(得分:0)

要强行重装,

document.getElementById('iframepdf').contentDocument.location.reload(true);

这也将改变页面和谷歌pdf查看器。