0

如何在更改父窗口的同时单击链接以在新窗口中打开 PDF?

就像是?…</p>

<a href="assets/pdf/a_pdf_doc.pdf" target="new"
   onclick="window.parent.location.href='newpage.html';">A PDF Doc</a>

当然以上不起作用....只是我认为接近答案的一个例子。谢谢!

4

2 回答 2

1

您可以将“新窗口”和“重定向”功能移动到单个 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,我会保留指定的常规属性。

于 2012-08-07T14:49:53.350 回答
0

尝试将链接更改为:

<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>
于 2012-08-07T14:48:01.257 回答