我在 Microsoft Edge 中发现了一个看似错误的问题。 setInterval() 的回调有时会在 print() 执行时调用。这会导致 2 个 JavaScript 函数并行运行,这是不允许的,对吗?
可以使用这个简单的测试应用程序观察该行为。
index.html:
<!DOCTYPE html>
<html>
<head>
<script src="script.js"></script>
</head>
<body>
<input type="button" onclick="printPage()" value="Print"/>
</body>
</html>
脚本.js:
var isPrinting = false;
setInterval(function tick() {
if (isPrinting) {
alert('Interval callback called conurrently with click handler!');
}
}, 10);
function printPage() {
isPrinting = true;
try {
print();
}
finally {
isPrinting = false;
}
}
https://plnkr.co/edit/eKMQEHjRiXzl1vzjzIEN
当我单击“打印”按钮时,我预计不会看到警报,但我确实观察到了警报。
环境:Microsoft Edge 38.14393.0.0、Windows 10
这是一个错误还是我不明白什么?
最佳答案
是的,这是一个已确认的错误。我有点惊讶的是,在我之前显然没有人报告过这一点。
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10230373/
关于javascript - 微软边缘: setInterval() callback called concurrently with print(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41153360/