Firefox (on Vista) onload alert problem

Hi Experts...

I have this odd problem that only affects Firefox on Vista(my version is 3.6.13 on Vista. The same version on XP seems to be OK!).

I have a script that outputs a simple page with an onload alert and a redirect to another URL. Like this for example:

<html>
<head>
</head>
<body onload="alert('test'); window.location.href='http://mydomain.com/test.html'">
<p>Testing</p>
</body>
</html>

Open in new window


What happens a lot (but not I think all the time!), is that the alert box is blank, until you move your mouse.

Any idea how I can fix that?

As I say, this is ONLY in Firefox. (Another difference between Firefox here and Chrome, IE, Opera and Safari is the other browsers display the new page content behind the alert box immediately, whereas Firefox only does so AFTER you press "OK" on the alert box. I wonder if this is a clue as to what's going on?)




PaliTreeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SnowFlakeCommented:
and what behavior do you want to get ?

maybe you can replace the alert with a div that has an "onclick" of its own that will only then do the redirect ?
PaliTreeAuthor Commented:
The behaviour I want to get is the same as other browsers ;-)

i.e. The alert message appears 'on load' (not a blank alert until you move your mouse). And after the alert, the page redirects. I don't want to use 'onclick' - it must be automatic 'on load'.

Michel PlungjanIT ExpertCommented:
Never had that.

I would personally do
<html>
<head>
<script type="text/javascript">
window.onload=function() {
  alert('You will be redirected');
  window.location.replace('http://mydomain.com/test.html');
}
</script>
</head>
<body>
<p>Testing</p>

Click here if you are not redirected: <a href="http://mydomain.com/test.html">Other site</a>

</body>
</html>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

PaliTreeAuthor Commented:
Thanks for that comment mplungjan.

Is there any reason why you'd prefer that way of doing it?

(BTW, I tried code like that to solve the problem, but it made no difference. Except I did "window.location.href" instead of "replace")
Michel PlungjanIT ExpertCommented:
It is cleaner and easier to change like below.

However if it does the same, then you have a very weird problem.

Try this
<html>
<head>
<script type="text/javascript">
window.onload=function() {
  alert('You will be redirected');
  var tId = setTimeout(function() {window.location.replace('http://mydomain.com/test.html')},300); // give the browser a few milliseconds to continue
}
</script>
</head>
<body>
<p>Testing</p>

Click here if you are not redirected: <a href="http://mydomain.com/test.html">Other site</a>

</body>
</html>

Open in new window

SnowFlakeCommented:
if mplungjan's code above does not work for you,
try to switch lines 6 and 5 just in case the alert is blocking the call to setTimeout.
Michel PlungjanIT ExpertCommented:
Erm not a good idea to try to leave a page and then try to execute script
SnowFlakeCommented:
that is not what I suggested,
I suggested the you call the set timeout (i.e. prepare to leave the site) and only then call the alert.
and I also said that this should be tried only if the original form of yor code did not work for him.
Michel PlungjanIT ExpertCommented:
But the timeout is 300 Milliseconds so not enough to wait while the user decides to dismiss the alert
PaliTreeAuthor Commented:
"However if it does the same, then you have a very weird problem."

I think this is just a flaky thing with Firefox and Vista that I've just got to live with.

Thanks guys for the suggestions - actually I can sometimes have the issue (blank modal alert box until mouse move) without the redirect! Anyhoo I've learnt something about how to code the redirect more elegantly...



PaliTreeAuthor Commented:
A helpful response. I think the core problem may be a bug in Firefox on Vista. Insoluble!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.