2017-01-22 115 views
1

我有這個JavaScript PHP頁面:window.print不工作了

function printStuff($stuffdetails) { 
<SCRIPT LANGUAGE="JavaScript" type="text/javascript"> 
window.print(); 
window.location = "<?=$stuffdetails['redirect']?>"; 
</script> 

沒有被打印出來。 當我刪除

window.location = "<?=$stuffdetails['redirect']?>";

的版畫作品。 任何想法是怎麼回事? 謝謝!

我找到了解決自己:

window.print(); 
    setTimeout (function() {delayRedirect();},100); 

    function delayRedirect() 
    {window.location.href = "<?=$stuffdetails['redirect']?>";} 

用小超時一切工作

+0

注:'LANGUAGE = 「JavaScript的」'是不是有點老派 – RiggsFolly

+0

你怎麼稱呼printStuff? –

+0

我有一個主要的PHP頁面,其中printStuff函數被調用:printStuff($ stuffdetails)。 printstuff函數位於主php頁面中的function.php頁面 – bashrael

回答

-1

正如你已經發現有問題的代碼行是

window.location = "<?=$stuffdetails['redirect']?>"; 

這是一個JavaScript代碼中寫入我們正在談論的function$stuffdetails['redirect']很可能未定義。執行以下操作:

function printStuff($stuffdetails) { 
<SCRIPT LANGUAGE="JavaScript" type="text/javascript"> 
<? 
    if (!isset($stuffdetails) || !isset($stuffdetails['redirect'])) { 
     alert("The bug is that $stuffdetails['redirect'] is not set!"); 
    } 
?> 
window.print(); 
window.location = "<?=$stuffdetails['redirect']?>"; 
</script> 
+0

任何投票原因? –

+0

試過這個,但沒有改變。爲了確保我將代碼更改爲: window.print(); window.location.href =「http://www.google.be」; 結果是一樣的。 PS。反對票不是我的。 – bashrael