2017-05-19 16 views
0

ローカルで美しく動作しますが、WordPressサイトにアップロードすると、新しいプリントウィンドウが開き、すぐにオン/オフ画面が点滅します。 Chromeでのみテストされ、私が言ったように、サーバーにアップロードするまで問題はありません。プリントウィンドウはローカルでは動作しますが、WordPressではありません

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); 

}

EDITED THE ABOVE(プリントウィンドウが今まで滞在、ドキュメントがありませんが、Chromeで表示しない。FFで動作します)

function printDiv(divName) { 

"厳格な使用" ;

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(); 

}

+0

あなたは[あなたのコンソールをチェックしましたか?](http://stackoverflow.com/documentation/javascript/185/getting-started-with-javascript/714/using-console-log) –

+0

私はそこにエラーを報告していません。私はスクリプトを使って遊んでいて、プリントウィンドウを持っていましたが、コンテンツはプレビューにはなく、空白が表示されます。しかし、Firefoxで働いています。 – flipflopmedia

答えて

0

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); 

return true; FYI

<button onclick="Javascript:printDiv('Print-Needs-LifeStyle-Life-Stage')">Print</button>

::}

、印刷ボタンのコードのための は(あなたが好きあなたのdiv要素には任意の名前を付ける)500に3000を変更し、印刷プレビューウィンドウが来るのを、それは時間がかかりすぎたために新しいウィンドウが開いた後に起動します。

関連する問題