We have a JavaScript function named \"move\" which does just \"windows.location.href = any given anchor\".
This function works on IE, Opera and Safari, but so
One observation to ensure in such a scenario
Following will work in IE
, but neither in Chrome
nor in Firefox
(the versions I tested)
window.location.href("http://stackoverflow.com");
Following will work all the three
window.location.href = "http://stackoverflow.com";
window.location.href works fine in all versions of Firefox, as does document.location.href I think that there is something else in your code that is breaking things.
drop this in a blank page, if it works, it indicates there is something else wrong on your page.
<script>
window.location.href = 'http://www.google.com/';
</script>
I just overcome the same problem. and the problem is not in javascript, but the href attribute on the <a>
element.
my js code
function sebelum_hapus()
{
var setuju = confirm ("Anda akan menghapus data...")
if (setuju)
window.location = "index.php";
}
my previous html was
<a href="" onClick="sebelum_hapus();">Klik here</a>
and I update it to
<a href="#" onClick="sebelum_hapus();">Klik here</a>
or remove the href attribute
hope this helps.
You could also use window.location.replace
to jump to an anchor without register it in the browser history:
This article illustrates how to jump to an anchor and uses href as read-only property.
function navigateNext()
{
if (!window.location.hash)
{
window.location.replace(window.location.href + unescape("#2"))
}
else
{
newItem = nextItem(window.location.hash)
if (document.getElementById(newItem))
{
window.location.replace(stripHash(window.location) + "#" + newItem)
}
else
{
window.location.replace(stripHash(window.location) + "#1")
}
}
}
For reference I had the same problem.
onclick = "javascript: window.location('example.html');" didn't work under FF (latest)
I just had to rewrite to onclick = "javascript: window.location = 'example.html';" to get it working
Have you tried just using
window.location = 'url';
In some browsers, window.location.href
is a read-only property and is not the best way to set the location (even though technically it should allow you to). If you use the location
property on its own, that should redirect for you in all browsers.
Mozilla's documentation has a pretty detailed explanation of how to use the window.location
object.
https://developer.mozilla.org/en/DOM/window.location