Safari not opening a href with window.location.href
17,102
Try with either document.location.href
or just location.href
.
Hey there. Your code should work. Well i tried this simple example on Safari browser and it works good. Try yourself.
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
function countClicks()
{
window.location.href = "http://www.stackoverflow.com";
}
</script>
</head>
<body onLoad=countClicks()>
</body>
</html>
Anchor Property : FYI : I have used window.open
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
function countClicks()
{
window.open("http://stackoverflow.com", "_blank");
}
</script>
</head>
<body>
<a href="#" name="xy" onclick="javascript:countClicks(this);">Visit StackOverflow Website</a>
</body>
</html>
Passing variables from function
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
function countClicks(a,b)
{
window.open("http://stackoverflow.com?id="+a+"&id2="+b, "_blank");
}
</script>
</head>
<body>
<a href="#" name="xy" onclick="javascript:countClicks(2,3);">test</a>
</body>
</html>
Author by
user1170040
Updated on June 04, 2022Comments
-
user1170040 almost 2 years
Safari ignores the a href link. Other browsers pass the countClicks function AND pass the link to open the new browser window. Any suggestions?
The JavaScript source is as follows:
<script language="JavaScript" type="text/JavaScript"> function countClicks(enterprise_code,sid_code,buspart_id,prod_id,server_name,path_info,query_string) { window.location.href = "/sharedInc/cf/polTrack.cfm?Buspart_id=" + buspart_id + "&Enterprise_Code=" + enterprise_code + "&Sid_Code=" + sid_code + "&Prod_id=" + prod_id + "&Server_Name=" + server_name + "&Path_Info=" + path_info + "&Query_String=" + query_string; } </script>
Whereas the HTML markup is:
<a href="http://www.polclients.com" target="_blank" onclick="countClicks('POL','POL',6808,387,'www.princetonol.com','/index.cfm','x=x&at=no')">Link</a>
-
Vitalik Teremasov over 9 yearsThe problem of this code is thet the opened window with new address can be blocked by popup blockers