简体   繁体   English

在window.open javascript之后刷新父页面,而子窗口包含window.print onload

[英]Refresh Parent Page after window.open javascript while child window contains window.print onload of it

I want to open a link in new tab and immediately refresh my page in JavaScript. 我想在新标签页中打开链接,并立即使用JavaScript刷新页面。 But when I open a new tab using window.open() , it does't reload my page. 但是,当我使用window.open()打开一个新标签时,它不会重新加载我的页面。 it waits for new tab to be closed then refresh my page. 它等待新标签页关闭然后刷新我的页面。 Although it works in IE. 虽然它在IE中有效。 But Chrome is waiting to child window to be closed. 但是Chrome浏览器正在等待子窗口关闭。

$.ajax({
    url: '/MailMan/Print'
    , dataType: "json"
    , type: "POST"
    , success: function (result) {
        if (result.success == true) {
            window.open(
                '/MailMan/Index/Building/1/Shift/1'
                , '_blank'
            );

            window.location.reload();
        }
    }

});

The child page contains window.print() command in onload() of it. 子页面的onload()中包含window.print()命令。 and when I close print dialog , main page refreshes successfully. 当我关闭打印对话框时,主页刷新成功。 This is my child page : 这是我的子页面:

<head>
<meta name="viewport" content="width=device-width" />
<script>
    window.onload = function () {
        window.print();
    }
</script>

</head>
<body>
</body>

I change my child window as below and it works for me. 我如下更改我的孩子窗口,它对我有用。 although it bring print dialog 1 sec later but it's not a big deal for me. 尽管它在1秒钟后带来了打印对话框,但这对我来说并不重要。

<head>
<meta name="viewport" content="width=device-width" />
<script>
    window.onload = function () {
        window.setTimeout(window.print(),1000
        );
}
</script>

</head>
<body>
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM