2017-01-22 119 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