Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window.location.href doesn't work in Safari

Status
Not open for further replies.

Niavlys

IS-IT--Management
Jun 3, 2002
197
CA
Hi,
I have a problem with window.location.href in Safari browser.

I have a link:
Code:
function ConfirmDelete(Url, Message)
{
    if (confirm(Message))
    {
    	window.location.href=Url
    }
}

<a href="#" onClick="ConfirmDelete('DeleteSelection.asp?sType=All&rPage=Portfolio', 'message')" >

This ask for a confirmation before deleting a file. It works well under Netscape, IE, Mozilla but not under Safari. When I click on OK to confirm, the confirm window disapears but I'm not redirected to the requested page.

Is there another function than window.location.href that would work under any browser or any hacks to it.

I'm really stuck, can you help me please!
 

The behaviour of Safari could almost be said to be more correct than the other browsers, given the code that you've shown.

Because your onclick code does not have a "return(false);" statement after it, the browser is going on to load the href you've specified ("#"). I guess that the other browsers you mention are running the JS, but ignoring the href, as the page location has already changed at that point.

Either way, if you change your onclick statement to read:

Code:
onclick="ConfirmDelete('DeleteSelection.asp?sType=All&rPage=Portfolio', 'message'); return(false);"

then all works as expected. It's great being able to debug Safari problems on a PC using PearPC, btw ;o)

Hope this helps,
Dan
 
Hi, thanks for the answer but it didn't fix the problem, I'm still having the same behaviour.

[sad]
 

Really? I took your code, put the correct HTML tags around it (I assume you have those in, but removed them from the post for brevity - if not, you might want to try adding them and making well-formed HTML before attempting to debug problems!), uploaded it to my server, and saw the problem. I added in the "return(false)", and the issue went away - so not sure (above reasons permitting) why you are still seeing the issue.

Can you post a link to your code?

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top