在Chrome中隐藏主窗口后面的弹出窗口

时间:2015-08-13 10:25:17

标签: javascript google-chrome printing

我想知道是否可以隐藏“主”窗口后面的弹出窗口,我使用的浏览器是最新的谷歌浏览器。

这是因为我每次用户按下按钮时都会调用这个javascript代码,打开一个窗口,然后打印并关闭窗口。

但是我希望它在“主”窗口后面打开,这样用户就不会真的看到它打开了。

有可能吗?

javascript代码:

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script> 
<script type="text/javascript">

    function PrintElem(elem)
    {
        Popup($(elem).html());
    }

    function Popup(data) 
    {
        var mywindow = window.open('', 'my div', 'height=400,width=600');
        mywindow.document.write('<html><head><title>my div</title>');
        /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');

        mywindow.document.close(); // necessary for IE >= 10
        mywindow.focus(); // necessary for IE >= 10

        mywindow.print();
        mywindow.close();

        return true;
    }

</script>

按钮和带文字的div

<div class="mydivID" style="display:none;">
   Hello
</div>

<a href="#" onclick="PrintElem('.mydivID')" />

以任何方式可行,如果是浏览器设置,或者在javascript中进行更改,则无关紧要。

希望你能帮忙:-)

0 个答案:

没有答案
相关问题