/    Sign up×
Community /Pin to ProfileBookmark

setTimeout behaves differently in IE and Netscape

Following code is counter which shows 10, 9, 8 till 1 then message box appears “BOOM”. “BOOM Now” is button which displays message box “BOOM”.

In IE
When you press “BOOM now” before countdown finished countdown stops till you press OK on message box

In Netscape
When you press “BOOM now” before countdown finished countdown still active and continue to work.

What I need
I would like message box in IE to behave similar to Netscape i.e. countdown should not stop.

[FONT=Courier New]<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Tester</title>

<script language=”javascript” type=”text/javascript”>

var timeLeft = 10;

function counter()
{
if(timeLeft>0)
{
document.getElementById(“timeLeft”).innerHTML = timeLeft;
timeLeft = timeLeft – 1;
setTimeout(‘counter()’, 1000);
}
else
alert(“BOOM”);
}

</script>

</head>

<body onload=”counter()”>
<div id=”timeLeft”></div>
<input name=”BOOM” value=”BOOM Now” type=”button” onclick=”alert(‘BOOM’)”/>
</body>

</html>[/FONT]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @pop spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...