When using the alert(message) function, it will display an alert box with a message and an OK button. It will also pause the execution of any code that follows until the OK button is clicked. However, I have noticed a peculiar situation where switching tabs from one page to another and then back again causes the code after the alert to execute while the alert box remains visible. Is this behavior intentional or a bug?
I have tested this in Firefox and IE without encountering the issue, but both Chrome and Edge exhibit the same behavior. Interestingly, the presence of developer tools can affect the outcome as well.
An example scenario:
After clicking on button1 to trigger the alert box, if you switch to another tab and return, the value of button2 changes to "123" while the alert box persists.
<html>
<head>
<script type = "text/javascript">
function fun() {
alert (" Hello World \n This is an alert dialog box ");
document.getElementById("test").setAttribute("value", 123);
}
function fun2() {
document.getElementById("test").setAttribute("value", "Test");
}
</script>
</head>
<body>
<p> Click the following button to see the effect </p>
<form>
<input type = "button" name="button1" value = "Click me" onclick = "fun();" />
<input type = "button" name="button2" id="test" value = "Test" onclick = "fun2()" />
</form>
</body>
</html>