2014-01-27 83 views
-1

我知道我所問的問題已經在此討論過了。但我無法找到任何明確的解決方案。 我正在致力於Drupal 7的一個項目,在那裏我想打印出來。我有圖表和一些其他內容要打印。我使用window.open()創建了新窗口,並將所有樣式和js(chart.js,jquery.js等)添加到新創建的窗口中以獲取樣式。和window.print()來打印。我的代碼在firefoxchrome中工作,但不在IE中。我附上了我在下面使用的代碼。Window.print()在ie中不起作用,但可以在所有其他瀏覽器中工作

var mywindow = window.open('', 'print', 'scrollbars=1,height=600,width=600'); 
mywindow.document.write("<html><head><title>Patient Data</title><link rel='stylesheet' type='text/css' href='" + Drupal.settings.basePath + "sites/all/themes/prescribewell/css/style.css'>"); 
mywindow.document.write("<link rel='stylesheet' type='text/css' href='" + Drupal.settings.basePath + "sites/all/themes/prescribewell/css/bootstrap.css'>"); 
mywindow.document.write("<link rel='stylesheet' type='text/css' href='" + Drupal.settings.basePath + "sites/all/themes/prescribewell/css/bootstrap.min.css'>"); 
mywindow.document.write("<link rel='stylesheet' type='text/css' href='" + Drupal.settings.basePath + "sites/all/themes/prescribewell/css/bootstrap-theme.css'>"); 
mywindow.document.write("<link rel='stylesheet' type='text/css' href='" + Drupal.settings.basePath + "sites/all/themes/prescribewell/css/bootstrap-theme.min.css'>"); 
mywindow.document.write("<link rel='stylesheet' type='text/css' href='" + Drupal.settings.basePath + "sites/all/themes/prescribewell/css/font-awesome.css'>"); 
mywindow.document.write("<link rel='stylesheet' type='text/css' href='" + Drupal.settings.basePath + "sites/all/themes/prescribewell/css/font-style.css'>"); 
mywindow.document.write("<script src='http://code.jquery.com/jquery-1.10.2.min.js'></sc" + "ript>"); 
mywindow.document.write("<script src='" + Drupal.settings.basePath + "sites/all/themes/prescribewell/js/bootstrap.js'></sc" + "ript>"); 
mywindow.document.write("<script src='" + Drupal.settings.basePath + "sites/all/themes/prescribewell/js/bootstrap.min.js'></sc" + "ript>"); 
mywindow.document.write("<script src='" + Drupal.settings.basePath + "sites/all/themes/prescribewell/js/button.js'></sc" + "ript>"); 
mywindow.document.write("<script src='" + Drupal.settings.basePath + "sites/all/themes/prescribewell/js/prescribewell_leads_js.js'></sc" + "ript>"); 
mywindow.document.write("<script src='" + Drupal.settings.basePath + "sites/all/modules/Prescribewell_leeds/prescription.js'></sc" + "ript>"); 

mywindow.document.write("</head><body>"); 
mywindow.document.write(datas.resPres); //content to be printed as json response... 

mywindow.document.write("</body>"); 
if (summary == 1) { 
    mywindow.document.write("<script src='http://code.jquery.com/jquery-1.10.2.min.js'></sc" + "ript>"); 
    mywindow.document.write("<script src='" + Drupal.settings.basePath + "sites/all/modules/prescribewell_charts/Chart.js'></sc" + "ript>"); 
    mywindow.document.write("<script src='" + Drupal.settings.basePath + "sites/all/modules/prescribewell_charts/clinicchart.js'></sc" + "ript>"); 
    mywindow.document.write("<script src='" + Drupal.settings.basePath + "sites/all/modules/Prescribewell_leeds/print.js'></sc" + "ript>"); 
} 
mywindow.document.write("</html>"); 

if (navigator.appName == 'Microsoft Internet Explorer') { 
    window.print(); 
} else { 

    setTimeout(function() { 

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

    }, 5000); 
} 

在此先感謝。

+0

向我們提供小提琴請 –

+2

您將不得不告訴我們您的調試已經顯示,不僅僅是「它不工作」。什麼_does_發生?什麼錯誤?你嘗試過哪些實驗? –

回答

1

你的代碼有一個條件IE:

if (navigator.appName == 'Microsoft Internet Explorer') { 
    window.print(); 
} else { 
    //other code 
} 

其他代碼塊是一個跨瀏覽器的,必須在IE瀏覽器:

mywindow.document.close();//close document after write 
mywindow.focus();//set focus back 
mywindow.print();//start print dialog 
//mywindow.close(); 

所以只要刪除if/elseIE檢查。

相關問題