如何在更改父窗口的同时单击链接以在新窗口中打开 PDF?
就像是?…</p>
<a href="assets/pdf/a_pdf_doc.pdf" target="new"
onclick="window.parent.location.href='newpage.html';">A PDF Doc</a>
当然以上不起作用....只是我认为接近答案的一个例子。谢谢!
如何在更改父窗口的同时单击链接以在新窗口中打开 PDF?
就像是?…</p>
<a href="assets/pdf/a_pdf_doc.pdf" target="new"
onclick="window.parent.location.href='newpage.html';">A PDF Doc</a>
当然以上不起作用....只是我认为接近答案的一个例子。谢谢!
您可以将“新窗口”和“重定向”功能移动到单个 JS 函数中。该定义可能如下所示:
<script type="text/javascript">
function openPdf(e, path, redirect) {
// stop the browser from going to the href
e = e || window.event; // for IE
e.preventDefault();
// launch a new window with your PDF
window.open(path, 'somename', ... /* options */);
// redirect current page to new location
window.location = redirect;
}
</script>
然后在您的 HTML 中:
<a href="assets/pdf/a_pdf_doc.pdf"
onclick="openPdf(event, 'assets/pdf/a_pdf_doc.pdf', 'newpage.html');">
A PDF Doc
</a>
href
如果用户关闭了 JS,我会保留指定的常规属性。
尝试将链接更改为:
<a href="javascript:void(0)" onclick="opentwowindows()">click me</a>
然后在当前页面和父页面创建一个javascript函数;就像是:
<script>
function opentwowindows() {
window.parent.location.href='newpage.html';
window.location.href="/anotherpage.html';
}
</script>