2017-07-23 84 views
0

嗨我試圖做打印頁面,但它必須首先打開頁面在一個新的選項卡。 我試着做代碼。從我的代碼中,我可以在新選項卡中打開頁面,但是打印功能會打印一個空白頁面,而不是我直接在新選項卡中打開的頁面。如何打開一個頁面到一個新的窗口並打印它

如何解決這個問題?請幫我

這是我的代碼

<script> 
 
\t function myFunction() { 
 
    \t w=window.open("../../192.168.1.22/print_page/SPL_Karyawan.html"); 
 
\t w.print(); 
 
\t w.close(); 
 
\t } 
 
\t 
 
\t </script>

+0

你的網址無效。 –

+0

多數民衆贊成在我的本地數據夥計url –

+0

是否要在新標籤頁或父標籤上打印? –

回答

-1

下面的代碼正在爲我的。

<html> 
<head> 
<script type="text/javascript"> 
function openNewWindow(){ 
var newWindow=window.open('redir2.html'); 
newWindow.focus(); 
newWindow.print(); 
newWindow.close(); 
} 
</script> 
</head> 
<body> 

<input type="button" value="Open new window" onclick="openNewWindow()" /> 

</body> 
</html> 

來源:http://jsfiddle.net/Q5Xc9/1/

基礎上的評論,在window.redirect定的路徑是錯誤的。它應該從帶有http的IP地址開始。

+0

仍然空白頁已打開在打印對話框 –

+0

也許我有錯誤的類型的路徑代碼? –

+1

ok done .. thx ..我剛剛在我的文檔路徑中出錯 –

相關問題