1

When I try open file dialog (input type=file) my JS code stopped executing in IE. Could you explain me why it happend? And how I can fix it?

JS:

    function Count() { 
    num++;
    document.timerform.clock.value = num;
    down = setTimeout("Count()", 1000);
    }
    function timeIt() {
    num=0;
    Count();
    }

HTML:

    <BODY OnLoad="timeIt()">
    <center>   
    <form name="timerform">
    <input type="text" name="clock" size="7" value="1:00"><p>
    <input type="file" name="datafile" size="40">
    </form>
    </center>

version vith iframe:

    <BODY OnLoad="timeIt()">
    <center>
    <form name="timerform">
    <input type="text" name="clock" size="7" value="1:00"><p>
    <iframe src="blank.html" height="200" width="500">My frame.</iframe>
    </form>
    </center>

blank.html:

    <input type="file" name="datafile" size="40">
0

2 Answers 2

1

That's the nature of the browser. There's nothing you can do about it. (aside from putting the file dialog in an Iframe)

Sign up to request clarification or add additional context in comments.

12 Comments

Do you mean that everything will just stop (hang) when file dialogue box will open and is it same for every browser ?
Tested it on Firefox and the counter keeps going. You can try it here on other browsers: jsfiddle.net/gq7ut
Worked on chrome 16.0.912.77 and ff 10.0 and also opera but didn't worked on ie8. Thanks !
Yeah, it works on any browsers, except IE. But I need it work on IE
OK, write to Microsoft. There is nothing you can do in JavaScript to change this. Considering using an Iframe. It's your only hope.
|
0

Javascript is single threaded. If you want a second counter to use setTimeout and not get way off because of javascript I suggest you use the Date object. Do the following:

var startTime = 0;
function Count() { 
    document.timerform.clock.value = Math.round((new Date().getTime() - startTime)/1000);
    down = setTimeout(Count, 1000);
}
function timeIt() {
    startTime = new Date().getTime();
    Count();
}

Then even if you have an event that takes control of the javascript thread you won't get off count once the count picks back up. You still want to avoid those situations, but don't ever count on setTimeout to be the exact time you set it to be.

1 Comment

I see. Yes it's useful notice. But even this script stop when file dialog open (document.timerform.clock.value - doesn't updated). My goal to receive the same behavior as in FF or Chrome if it possible

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.