Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Window.open冻结页面_Javascript_Jquery_Html_Css_Printing - Fatal编程技术网

Javascript Window.open冻结页面

Javascript Window.open冻结页面,javascript,jquery,html,css,printing,Javascript,Jquery,Html,Css,Printing,我正在尝试使用JS中的弹出窗口方法在我的页面上打印图像 当我单击居中图像的打印按钮时,会出现打印提示,但悬停效果会被冻结,单击事件不再起作用 这是我正在处理的页面: 这是功能和打印按钮的相关代码: $(document).ready(function(){ $( '#printbtn' ).hover(function() { $( '#couponhover' ).fadeIn( 200 ); },function() { $( '#couponhover' ).fadeOut

我正在尝试使用JS中的弹出窗口方法在我的页面上打印图像

当我单击居中图像的打印按钮时,会出现打印提示,但悬停效果会被冻结,单击事件不再起作用

这是我正在处理的页面:

这是功能和打印按钮的相关代码:

  $(document).ready(function(){
  $( '#printbtn' ).hover(function() {
  $( '#couponhover' ).fadeIn( 200 );
},function() {
  $( '#couponhover' ).fadeOut( 200 );
}
);});


function printImg()
    {
            var printWindow = window.open('', 'Print','height=400,width=600');
            printWindow.document.write('<html><head><title>Print Window</title>');
            printWindow.document.write('</head><body ><img src=\'');
            printWindow.document.write('coupon.jpg');
            printWindow.document.write('\' /></body></html>');
            printWindow.document.close();
            printWindow.print();
    }


        //HTML SNIPPET
        <a id="printbtn" href="javascript:printImg();" ></a>

您的document.write调用可能对此负责。改为使用document.createElement,它可能会解决您的问题,更不用说是正确的方法了。除非您发布相关代码,否则很难看到问题。不太可能只有window.open导致了该问题。@IvyLynx如何使用createElement?我应该用document.createElement替换document.write吗?@SamDenton你说得对,他补充道code@user3160630或多或少,是的,但您必须单独执行每个元素,并使用foo.appendChildbar连接它们,其中foo和bar是您创建的元素,这样您就可以将bar作为子元素放置在foo中。在这里看到更多。