这是铬错误吗?我该如何解决?:它跳过了开场白函数中的一些警报注释



我弹出了一个弹出窗口。弹出窗口调用了开瓶器的功能,该函数具有一些警报。 但是,Chrome跳过了上一个警报并执行了最后一个警报。

这是Chrome浏览器的错误吗?

主.html

<html>
<head>
<script type="text/javascript"><!--
function popUp(){
winobject = window.open("pop.html", "popName","left=100,top=100,toolbar=no,status=yes,menubar=no,width=200,height=200");
}
function fnCallBack(param) {
alert("1. msg (" + param + ")");
alert("2. msg (" + param + ")");
}
function alertN() {
		alert("1. alert");
		alert("2. alert");
}
</script>
</head>
<body>
	<input type="button" value="alertN" onclick="alertN();" onkeypress="alertN();" />
	<input type="button" value="popUp" onclick="popUp();" onkeypress="popUp();" />
</body>
</html>

啪.html

<html>
<head> 
<script type="text/javaScript" ><!--
function pressOk(){
opener.fnCallBack("From Pop");
	    	window.close();
}
</script>
</head>
<body>
<input type="button" value="OK" onclick="pressOk();" />
</body>
</html>

当我在弹出窗口中按"确定"按钮时,Chrome 只显示"2.味精..."。

这是因为Chrome的对话政策:

alert()对话框不会激活其选项卡。如果从后台选项卡调用alert(),则调用会立即返回。选项卡标有指示器,用户在切换到选项卡时将看到对话框。

所以这里发生的事情是,当调用第一个alert()时,主选项卡在后台,所以调用会立即返回,而不是停止代码执行。这会导致执行第二个alert(),但页面仍在后台,因此调用也会立即返回。然后,该函数完成并执行window.close()。弹出窗口关闭,焦点返回到主页。最后,由于第二个alert()是最后一个要执行的,因此 Chrome 会显示第二条消息。

将这种行为与 Firefox 进行比较,Firefox 不会立即从后台页面上的alert()调用中返回 - 您将看到两条消息,弹出窗口将保持打开状态,直到您在第二条消息上单击"确定"。

最新更新