I am using the following simple javasc开发者_StackOverflow社区ript for redirection. However, it works in some machine but not others. Does anybody know why? Is there a better way to make sure every machine works? I also tried <meta>
redirect it has the same issue.
<script type="text/javascript">
<!--
window.location = "http://mypage.html#instruction"
//-->
</script>
I would normally use the href
property of location
:
<script type="text/javascript">
<!--
window.location.href = "http://www.example.com/mypage.html#instruction"
//-->
</script>
Are you getting any javascript errors?
you can also try to use location.replace() method to load new url.
Maybe because your URL is wrong and some browsers are being generous? http://mypage.html#instruction
is probably not the URL you want. Perhaps just mypage.html#instruction
without the http://
or maybe /path/mypage.html
if it's on the same server, or http://server.name.com/mypage.html#instruction
.
As a fallback, you should probably include HTML like
Please <a href="http://server.com/mypage.html#instruction">click here</a>
for browsers that just don't run the script for whatever reason.
The most compatible way to do this is with a Meta refresh.
You just put this into your HTML HEAD tag:
<meta http-equiv="refresh" content="5;url=http://example.com/" />
I don't know why they say it is deprecated/discouraged, since it has been supported for many years and does not require any Javascript. It is discouraged because of usability, but that's another concern.
精彩评论