[英]How to click on a link to open a PDF in a new window while at the same time changing the parent window?
How to click on a link to open a PDF in a new window while at the same time changing the parent window? 如何单击链接以在新窗口中打开PDF,同时更改父窗口?
Something like? 就像是? … …
<a href="assets/pdf/a_pdf_doc.pdf" target="new"
onclick="window.parent.location.href='newpage.html';">A PDF Doc</a>
Of course the above doesn't work....just an example of what I perceive to be close to the answer. 当然,上面的方法是行不通的……只是我认为接近答案的一个例子。 Thanks! 谢谢!
You could move the "new window" and the "redirect" functionality into a single JS function. 您可以将“新窗口”和“重定向”功能移动到单个JS函数中。 Here's what that definition might look like: 该定义可能如下所示:
<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>
And then in your HTML: 然后在您的HTML中:
<a href="assets/pdf/a_pdf_doc.pdf"
onclick="openPdf(event, 'assets/pdf/a_pdf_doc.pdf', 'newpage.html');">
A PDF Doc
</a>
I would keep the regular href
attribute specified in case a user has JS turned off. 我会保留指定的常规href
属性,以防用户关闭JS。
try changing the link to: 尝试将链接更改为:
<a href="javascript:void(0)" onclick="opentwowindows()">click me</a>
and then create a javascript function the current page and the parent page; 然后在当前页面和父页面上创建一个javascript函数; something like: 就像是:
<script>
function opentwowindows() {
window.parent.location.href='newpage.html';
window.location.href="/anotherpage.html';
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.