Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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
Jquery element print preview是空白的,在Google Chrome中打印空白页面_Jquery_Google Chrome - Fatal编程技术网

Jquery element print preview是空白的,在Google Chrome中打印空白页面

Jquery element print preview是空白的,在Google Chrome中打印空白页面,jquery,google-chrome,Jquery,Google Chrome,我正在使用来自的jQuery代码打印覆盖div的内容: function PrintElem(elem){ Popup($(elem).html()); } function Popup(data) { var mywindow = window.open('', 'title', 'height=666,width=1000'); mywindow.document.write('<html><head><title>

我正在使用来自的jQuery代码打印覆盖div的内容:

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

   function Popup(data) 
{
    var mywindow = window.open('', 'title', 'height=666,width=1000');
    mywindow.document.write('<html><head><title>title-title</title>');
    /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
    mywindow.document.write('<link rel="stylesheet" href="includes/css/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;
}
但这完全破坏了函数,我想是因为那行中的
标记

这就是我的已修改函数的外观:

    function Popup(data) 
    {
        var mywindow = window.open('', '.com Shopping Cart', 'height=666,width=1000');
        mywindow.document.write('<html><head><title>- Shopping Cart</title>');
        /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
        mywindow.document.write('<link rel="stylesheet" href="includes/css/main.css" type="text/css" />');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);

        mywindow.document.write('<script type="text/javascript">$(window).load(function() { window.print(); window.close(); });</script>');


        mywindow.document.write('</body></html>');

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

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

        return true;
    }
功能弹出窗口(数据)
{
var mywindow=window.open(“”,“.com购物车”,“高度=666,宽度=1000”);
mywindow.document.write('-Shopping Cart');
/*可选样式表*///mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(数据);
mywindow.document.write('$(window.load)(function(){window.print();window.close();});');
mywindow.document.write(“”);
mywindow.document.close();//对于IE>=10是必需的
mywindow.focus();//IE>=10所必需的
//mywindow.print();
//mywindow.close();
返回true;
}
由于
标记正在破坏代码,请尝试使用以下行:

mywindow.document.write('<scr'+'ipt type="text/javascript">$(window).load(function() { window.print(); window.close(); });</scr'+'ipt>')
mywindow.document.write('$(window.load)(function(){window.print();window.close();});'))
如果没有jQuery:

mywindow.document.write('<scr'+'ipt type="text/javascript">function PrintPage() { window.print(); window.close(); } window.onload = PrintPage;</scr'+'ipt>');
mywindow.document.write('function PrintPage(){window.print();window.close();}window.onload=PrintPage;');

您可以延迟print()事件,让窗口先加载,而不是将Javascript或Jquery添加到新窗口的内容中

function Popup(data) 
{
    var mywindow = window.open('', '316steel.com Shopping Cart', 'height=666,width=1000');
    mywindow.document.write('<html><head><title>316steel Jewelry Corporation - Shopping Cart</title>');
    /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
    mywindow.document.write('<link rel="stylesheet" href="includes/css/main.css" type="text/css" />');
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);

    mywindow.document.write('</body></html>');

   /* Delaying the print event */ 
   setInterval(function () { 
      mywindow.document.close();
      mywindow.focus();
      mywindow.print();
      mywindow.close();    
    }, 100);

    return true;
}
功能弹出窗口(数据)
{
var mywindow=window.open(“”,'316steel.com购物车','height=666,width=1000');
mywindow.document.write('316steel Jewelry Corporation-购物车');
/*可选样式表*///mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(数据);
mywindow.document.write(“”);
/*延迟打印事件*/
setInterval(函数(){
mywindow.document.close();
mywindow.focus();
mywindow.print();
mywindow.close();
}, 100);
返回true;
}
我喜欢,但那不适合我。我使用了这个稍加修改的代码,它适用于IE、FireFox、Chrome和Safari。Chrome和Safari似乎需要延迟才能正常工作。希望这对别人有帮助

function Popup(data) 
{
    var mywindow = window.open('', '316steel.com Shopping Cart', 'height=666,width=1000');
    mywindow.document.write('<html><head><title>316steel Jewelry Corporation - Shopping Cart</title>');
    /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
    mywindow.document.write('<link rel="stylesheet" href="includes/css/main.css" type="text/css" />');
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);

    mywindow.document.write('</body></html>');
    mywindow.document.close();
    mywindow.focus();

   /* Delaying the print event */ 
   setInterval(function () { 
      mywindow.print();
      mywindow.close();    
    }, 100);

    return true;
}
功能弹出窗口(数据)
{
var mywindow=window.open(“”,'316steel.com购物车','height=666,width=1000');
mywindow.document.write('316steel Jewelry Corporation-购物车');
/*可选样式表*///mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(数据);
mywindow.document.write(“”);
mywindow.document.close();
mywindow.focus();
/*延迟打印事件*/
setInterval(函数(){
mywindow.print();
mywindow.close();
}, 100);
返回true;
}

通过使用setTimeOut函数,您应该能够解决您的问题

function Popup(data) 
{
    var mywindow = window.open('', '316steel.com Shopping Cart', 'height=666,width=1000');
    mywindow.document.write('<html><head><title>316steel Jewelry Corporation - Shopping Cart</title>');
    /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
    mywindow.document.write('<link rel="stylesheet" href="includes/css/main.css" type="text/css" />');
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);

    mywindow.document.write('</body></html>');
    mywindow.document.close();
    mywindow.focus();

   /* Delaying the print event */ 
    setTimeout(function () {           
            mywindow.print();
            mywindow.close();
        }, 2000);

    return true;
}
功能弹出窗口(数据)
{
var mywindow=window.open(“”,'316steel.com购物车','height=666,width=1000');
mywindow.document.write('316steel Jewelry Corporation-购物车');
/*可选样式表*///mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(“”);
mywindow.document.write(数据);
mywindow.document.write(“”);
mywindow.document.close();
mywindow.focus();
/*延迟打印事件*/
setTimeout(函数(){
mywindow.print();
mywindow.close();
}, 2000);
返回true;
}
function Popup(data) 
{
    var mywindow = window.open('', '316steel.com Shopping Cart', 'height=666,width=1000');
    mywindow.document.write('<html><head><title>316steel Jewelry Corporation - Shopping Cart</title>');
    /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
    mywindow.document.write('<link rel="stylesheet" href="includes/css/main.css" type="text/css" />');
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);

    mywindow.document.write('</body></html>');
    mywindow.document.close();
    mywindow.focus();

   /* Delaying the print event */ 
    setTimeout(function () {           
            mywindow.print();
            mywindow.close();
        }, 2000);

    return true;
}