Javascript 打印窗口在本地工作,但不在站点上使用WordPress

Javascript 打印窗口在本地工作,但不在站点上使用WordPress,javascript,wordpress,printing,window,Javascript,Wordpress,Printing,Window,它在本地运行得很好,但当我上传到WordPress网站时,新的打印窗口会打开,并立即在屏幕上/屏幕下闪烁。只测试了Chrome,就像我说的,我没有问题,直到我上传到服务器 Javascript: function printDiv(divName) { "use strict"; var divToPrint = document.getElementById(divName); var WindowObject = window.open('', 'PrintWindow', 'width

它在本地运行得很好,但当我上传到WordPress网站时,新的打印窗口会打开,并立即在屏幕上/屏幕下闪烁。只测试了Chrome,就像我说的,我没有问题,直到我上传到服务器

Javascript:

function printDiv(divName) {

"use strict";
var divToPrint = document.getElementById(divName);

var WindowObject = window.open('', 'PrintWindow', 'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
WindowObject.document.writeln('<!DOCTYPE html>');
WindowObject.document.writeln('<html><head><title>Your Safari Print Results</title>');
WindowObject.document.writeln('<link rel="stylesheet" id="fonts-googleapis-css"  href="http://fonts.googleapis.com/css?family=Lato%3A400%2C100%2C300%2C700%2C900&#038;ver=4.6" type="text/css" media="all">');
WindowObject.document.writeln('<link rel="stylesheet" type="text/css" href="NewWinPrintScreen_hmap.css">');
WindowObject.document.writeln('</head><body onload="window.print()"><center><img src="logo.png" width="219" height="78"><br><div class="line"></div></center><br><br><span class="pg_title">Canine Wellness HealthMap</span>');

WindowObject.document.writeln(divToPrint.innerHTML);

WindowObject.document.writeln('</body></html>');

WindowObject.document.close();
setTimeout(function () { WindowObject.close(); }, 500);
“严格使用”

var WindowObject=window.open(“”,'PrintWindow','width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
var divToPrint=document.getElementById(divName);
WindowObject.document.writeln(“您的Safari打印结果


犬类健康地图”); WindowObject.document.writeln(divToPrint.innerHTML); WindowObject.document.writeln(“”); /*延迟打印事件*/ setInterval(函数(){},100); WindowObject.focus(); WindowObject.print(); WindowObject.close();

}

让它在Chrome中正常工作。打开打印窗口,预览并随后关闭。在这段代码和确保jQuery已加载之间,它现在在Chrome中完全可以正常工作了

此脚本允许您在同一页上打印多个/单独的div。将打印按钮指定给DIV,它将打印该DIV

function printDiv(divName) { // jshint ignore:line

"use strict";
var divToPrint = document.getElementById(divName);
var mywindow = window.open('', 'PrintWindow', 'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
mywindow.document.write('<html><head><title>Your Safari Print Results</title><link rel="stylesheet" type="text/css" href="css/NewWinPrintScreen_hmap.css"></head>');
mywindow.document.write('<body><center><img src="images/logo.png" width="219" height="78"><br><div class="line"></div></center><br><br><span class="pg_title">Canine Wellness HealthMap</span>');

mywindow.document.write(divToPrint.innerHTML);

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

setTimeout(function() { // wait until all resources loaded 
    mywindow.document.close(); // necessary for IE >= 10
    mywindow.focus(); // necessary for IE >= 10
    mywindow.print(); // change window to winPrint
    mywindow.close(); // change window to winPrint
 }, 3000);
函数printDiv(divName){//jshint ignore:line
“严格使用”;
var divToPrint=document.getElementById(divName);
var mywindow=window.open(“”,'PrintWindow','width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
mywindow.document.write('您的Safari打印结果');
mywindow.document.write(“


犬类健康地图”); mywindow.document.write(divToPrint.innerHTML); mywindow.document.write(“”); setTimeout(函数(){//等待所有资源加载 mywindow.document.close();//对于IE>=10是必需的 mywindow.focus();//IE>=10所必需的 mywindow.print();//将窗口更改为winPrint mywindow.close();//将窗口更改为winPrint }, 3000);
返回true; }

对于打印按钮代码(可以随意命名您的div):

打印


仅供参考:已将3000更改为500,因为新窗口打开后打印预览窗口出现的时间太长。

没有给我任何错误信息。我对脚本进行了修改,并在打印窗口中将其保留下来,但内容不在预览中,它打印为空白。在Firefox中工作。
var WindowObject = window.open('', 'PrintWindow', 'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
var divToPrint = document.getElementById(divName);
WindowObject.document.writeln('<!DOCTYPE html><html><head><title>Your Safari Print Results</title><link rel="stylesheet" type="text/css" href="css/NewWinPrintScreen_hmap.css"></head><body><center><img src="images/logo.png" width="219" height="78"><br><div class="line"></div></center><br><br><span class="pg_title">Canine Wellness HealthMap</span>');
WindowObject.document.writeln(divToPrint.innerHTML);

WindowObject.document.writeln('</body></html>');

 /* Delaying the print event */ 
setInterval(function () {     }, 100);
  WindowObject.focus();
  WindowObject.print();
  WindowObject.close();
function printDiv(divName) { // jshint ignore:line

"use strict";
var divToPrint = document.getElementById(divName);
var mywindow = window.open('', 'PrintWindow', 'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
mywindow.document.write('<html><head><title>Your Safari Print Results</title><link rel="stylesheet" type="text/css" href="css/NewWinPrintScreen_hmap.css"></head>');
mywindow.document.write('<body><center><img src="images/logo.png" width="219" height="78"><br><div class="line"></div></center><br><br><span class="pg_title">Canine Wellness HealthMap</span>');

mywindow.document.write(divToPrint.innerHTML);

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

setTimeout(function() { // wait until all resources loaded 
    mywindow.document.close(); // necessary for IE >= 10
    mywindow.focus(); // necessary for IE >= 10
    mywindow.print(); // change window to winPrint
    mywindow.close(); // change window to winPrint
 }, 3000);