setTimeout(" window.close()",100)无法在Firefox

时间:2015-05-13 07:46:59

标签: javascript php firefox

我是HTML,PHP,Javascript的学习者。

我目前正在研究条形码扫描系统。步骤很简单,按订单号扫描,系统(表格)将生成另一个序列号,并立即将其与扫描的订单号一起打印出来,以便仓库工人可以将打印件粘贴在扫描的包裹上。 同样的步骤一直持续到完整的货物记录。

我们已经创建了一个简化程序并对其进行测试。如果它工作,那么我们可以遵循相同的逻辑来创建实际的表单。

到目前为止,我们已成功扫描条形码,然后使用windows.open跳转到另一个表单。在这个弹出窗口中,它是由FPDF创建的PDF文档。通过启用FIREFOX静音打印功能。弹出窗体可以自动打印出标签。一切都很好,除了我们无法关闭弹出窗口。我们已经挖掘出各种可能性并通过网络搜索......无法找到任何东西。 我们确实将Firefox选项dom.allow_scripts_to_close_windows设置为TRUE

第一种形式

<?PHP
session_start();
if (isset($_POST['submit'])){
$_SESSION['CUSTNO']=$_REQUEST['CUSTNO'];
$_SESSION['ORDERNO']=$_REQUEST['ORDERNO']   ;
//header('Location:TESTwai.php');
echo "myFunction();";
}
?>


<html>

<body>
<form action="" method="post" name="form1"><br>
<input type="text" id="CUSTNO" name="CUSTNO"  style="font-size: 24pt"/>
<input type="text" id="ORDERNO" name="ORDERNO"  style="font-size: 24pt"/>
<br>
<input name="submit" type="submit" value="SUBMIT" onclick="return myFunction()"></form>
</body>
</html>
<script>
function myFunction() {
    //window.open("ex.php","", "width=200, height=100");
    window.open("ex.php","", "width=1000, height=1000");

    myWindow.close();   // Closes the new window

}
</script>

第二个弹出窗口 我已将setTimeoutclose.window置于PHP脚本内部或外部,但仍然没有运气。

<?php

require('pdf_js.php');


class PDF_AutoPrint extends PDF_JavaScript
{
function AutoPrint($dialog=false)
{

    //Open the print dialog or start printing immediately on the standard printer
    //$param=($dialog ? 'true' : 'false');
    //echo $param;
    //$script="print($param);";
    $script="print(false);";
    $this->IncludeJS($script);
}
}
$pdf=new PDF_AutoPrint();
$pdf->AddPage();
$pdf->SetFont('Arial','',20);
$pdf->Text(90, 50, 'Print me!');
//Open the print dialog
$pdf->AutoPrint('false');
ob_end_clean();
$pdf->Output();

?>
<script>
setTimeout("window.close()", 100);
</script>

请忽略这些客户,orderno 。他们只是虚拟输入...

实际测试只是 1)按提交按钮 2)弹出窗口 3)在没有任何系统提示的情况下自动打印标签 4)关闭弹出窗口并返回第一个表单(卡在这里)

1 个答案:

答案 0 :(得分:0)

这不是setTimeout方法的问题。这是window.close()的问题。关闭窗口本身并不是一个好习惯。
如果您非常有必要,可以尝试以下代码:

window.open('','_parent',''); //fool the browser that it was opened with a script
window.close(); 

你可以把它放在一个函数中并在setTimeout中调用它。Helpful link