Subject: location.replace not working, any ideas?
Posted By: swin Post Date: 2/13/2006 10:11:27 PM
Hi,

I'm trying to create a confirmation box for deleting a record in a MySQL database. Upon selecting yes I would like to navigate to another page which will run the PHP script. The problem I'm having is that I can't get the browser to redirect upon responding to the confirmation box.

In Firefox it simply stays at the source page(viewevent.php). In IE it redirects me to my index.php regardless of the response.


    <script language="JavaScript" type="text/JavaScript">        
    function DeleteEvent(id, name)
    {
      var eventid= id;
      var eventname= name;
      var deleteconfirm= confirm("Do you really want to delete event: "+eventid+" - "+eventname+"?");
      
      if (deleteconfirm== true) {
        window.location.replace("deleteevent.php?eventid="+eventid);
      }
    }
    </script>


If anyone could shed some light on this it would be much appreciated as it's driving me bonkers!

Many Thanks
Swin


Reply By: vinod_yadav1919 Reply Date: 2/14/2006 12:40:44 AM
Hii Swin!!

Check whether browser support location.replace or not.
e.g.
You can use following code
<script>
<!--
  var version_val = parseInt(navigator.appVersion)
  //Check whether replace is supported or not
  if (version_val>=4 || window.location.replace)
            window.location.replace("deleteevent.php?eventid="+eventid);
  else
    window.location.href ="deleteevent.php?eventid="+eventid
// -->
</script>

Hope this will help you


Cheers :)

vinod
Reply By: Kong Reply Date: 2/14/2006 9:52:01 AM
The following code works fine and is identical to yours but deleteevent.php is replaced by http://www.cnn.com.

Therefore I am assuming that deleteevent.php is not located in the same folder as the redirect page?

<script language="JavaScript" type="text/JavaScript">        
    function DeleteEvent(id, name)
    {
      var eventid= id;
      var eventname= name;
      var deleteconfirm= confirm("Do you really want to delete event: "+eventid+" - "+eventname+"?");
      
      if (deleteconfirm== true) {
        window.location.replace("http://www.cnn.com");
      }
    }
 </script>



Reply By: swin Reply Date: 2/14/2006 2:35:05 PM
Thanks Kong, but it doesn't redirect even if I use an absolute url for the destination.

The following code is in the head section of a page called viewevent.php:


    <script language="JavaScript" type="text/JavaScript">        
    function DeleteEvent(id, name)
    {
      var eventid= id;
      var eventname= name;
      var deleteconfirm= confirm("Do you really want to delete event: "+eventid+" - "+eventname+"?");
      
      if (deleteconfirm== true) {
        window.location.replace("deleteevent.php?eventid="+eventid);
      }
    }
    </script>


The function is triggered by various links further down in the body of the page:


<td id="link"><a href="" onclick="DeleteEvent('$id','$name')">Delete</a></td>


$id and $name are php variables

The destination deleteevent.php is located within the same directory as viewevent.php.

---

Vinod

I had already tried using window.location, but I did try using your script just to be sure, unfortunately it still didn't solve the problem. I'm using the latest versions of IE and Firefox so that shouldn't be the issue, although it's definitely a good idea for older compatibility.

----

So anyone got any other ideas?

Reply By: Kong Reply Date: 2/15/2006 5:57:38 AM
Ah ok. I think your problem may be the empty href. Try writing <a href="#">.


Go to topic 40071

Return to index page 369
Return to index page 368
Return to index page 367
Return to index page 366
Return to index page 365
Return to index page 364
Return to index page 363
Return to index page 362
Return to index page 361
Return to index page 360