Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Script works in FF, but not in IE

    Hello hello

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

    PHP Code:
    <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
    Relax, everything is going perfectly out of control

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    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.
    Code:
    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.
    Code:
    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';
    }
    Last edited by Bill Posters; 05-28-2006 at 03:45 PM.

  • #3
    New Coder
    Join Date
    Jan 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, works beautifully now

    Dunno why I used setTimeout :P Late-at-night coding probably
    Relax, everything is going perfectly out of control

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Make it shorter:
    PHP Code:
    <script type="text/javascript">
    var 
    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> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by Kor
    Make it shorter:
    All in one statement and shorter still:
    PHP Code:
    <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> 
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •