2014-12-04 52 views
0

爲了讓我打印預覽「接受」的風格,我需要,包括我的彈出窗口,我使用的打印中的一個函數:如何包括window.open內的jQuery函數

功能我使用的打印是:

$('#printPersonnel').click(function() { 
      var data = document.getElementById('personnelTable').outerHTML; 
      var mywindow = window.open('', data); 
      mywindow.document.write('<html><head><title>NORA Loading</title>'); 
      mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Content/Site.css">'); 
      mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Scripts/examples-offline.css">'); 
      mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Scripts/kendo.rtl.min.css">'); 
      mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Scripts/kendo.common.min.css">'); 
      mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Scripts/kendo.dataviz.default.min.css">'); 
      mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Scripts/kendo.dataviz.min.css">'); 
      mywindow.document.write('<link rel="stylesheet" type="text/css" href="http://localhost:49573/Scripts/kendo.default.min.css">'); 

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

      mywindow.document.close(); 
      mywindow.focus(); 
      mywindow.print(); 
      mywindow.close(); 
      return true; 
     }); 

不過,我需要包括以正確添加此格式(我使用Telerik的UI格)一$(document).ready功能。

這意味着,我需要包括我的文檔中的腳本標記。

我的問題在於試圖添加結束腳本標籤(它把自己看作父頁面的一部分,而不是內部的功能)。

任何建議,我怎麼能實現這個功能?


我想某個表的標籤,這是在文件準備在頁面加載看作是一個Telerik的網格格式化內打印一切


編輯

我的問題是與mywindow腳本的結束標記:

mywindow.document.write('});'); 
mywindow.document.write('</script>'); //issue with this line/seen as esc sequence (i think) 

enter image description here

+0

你能提供包括''」);'工作,可能是問題在於裏面'.ready'函數體,語法錯誤還是什麼? – Zudwa 2014-12-04 12:57:26

回答

1

你可以用反斜槓與最終的腳本。

mywindow.document.write("<script>(function(){alert('1');})();<\/script>"); 
1

您可以分割成</script>部分,所以它不會被視爲結束標籤:

mywindow.document.write("<script>(function(){alert('1');})();" + "<" + "/script>"); 
+1

IIRC,這應該解決它。 ***更新*** http://stackoverflow.com/a/236106/1414562 – 2014-12-04 13:28:13

+0

@ A.沃爾夫你是對的。編碼'<'甚至是更好的方法(恕我直言)。 – Zudwa 2014-12-04 13:37:48