...

View Full Version : Script works in FF, but not in IE



Jonhoo
05-28-2006, 02:39 PM
Hello hello :)

I have made a small javascript for confirmation of deleting of a news article on my webpage.. It looks like this:


<script type="text/javascript">
var confirm = confirm("Are you sure you want to delete the article: 'Article name here' by Author name here?");

if (confirm == true)
{setTimeout("top.location.href = 'http://www.domain.com/ok.php'", 1);}
else
{setTimeout("top.location.href = 'http://www.domain.com/failed.php'", 1);}
</script>

The problem occurs when I try to actually click the link which produces the page with the code above.. In FF I get a confirmation popup, and then I get redirected to the appropriate page.. In IE however, all I get is the small annoying warning sign in the bottom left corner saying "Finished, but the page may contain errors"

Can any of you see the error with the above script..?

Appreciate any help :)
Jon

Bill Posters
05-28-2006, 03:19 PM
It may be the fact that you're using the word confirm to name the object.
IE/Win is known for confusing its object and method names, etc…

Try changing it to (e.g.) confirmation and see if that fixes things.

i.e.

var confirmation = confirm("Are you sure you want to delete the article: 'Article name here' by Author name here?");

if (confirmation) {
setTimeout("top.location.href = 'http://www.domain.com/ok.php'", 1);
} else {
setTimeout("top.location.href = 'http://www.domain.com/failed.php'", 1);
}

incidentally, why are you using setTimeout. Your delay is only 1/1000 of a second, so is effectively without delay - in which case, why bother?

e.g.

var confirmation = confirm("Are you sure you want to delete the article: 'Article name here' by Author name here?");

if (confirmation) {
top.location.href = 'http://www.domain.com/ok.php';
} else {
top.location.href = 'http://www.domain.com/failed.php';
}

Jonhoo
05-28-2006, 04:25 PM
Thanks, works beautifully now :D

Dunno why I used setTimeout :P Late-at-night coding probably ;)

Kor
05-28-2006, 06:12 PM
Make it shorter:


<script type="text/javascript">
var c = confirm("Are you sure you want to delete the article: 'Article name here' by Author name here?");
top.location.href=c?'http://www.domain.com/ok.php':'http://www.domain.com/failed.php';
</script>

felgall
05-28-2006, 10:17 PM
Make it shorter:

All in one statement and shorter still:


<script type="text/javascript">
top.location.href=confirm("Are you sure you want to delete the article: 'Article name here' by Author name here?")?'http://www.domain.com/ok.php':'http://www.domain.com/failed.php';
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum