I am facing on strange problem in ie6.
When i am using window.location to redirect page through javascript it开发者_高级运维 works fine in all browser except ie6.
It works in ie 6 if i place just like below:
<a href="javascript:void(0);" onclick="javascript:window.location('http://www.demo.com');">demo</a>
but its not working for below code.
<a href="javascript:void(0);" onclick="javascript:redirect();>demo</a>
function redirect()
{
window.location('http://www.demo.com');"
}
can you please figure out that whats problem here.
Thanks.
Avinash
The javascript:
protocol is only used if you have Javascript code in an URL. If you put it in an event handler it becomes a label instead.
The location
member is not a function, it's an object. Set the href
property to change the location.
You have an extra quotation mark after the code line in the function, which is probably causing a syntax error.
<a href="javascript:void(0);" onclick="redirect();>demo</a>
<script type="text/javascript">
function redirect() {
window.location.href = 'http://www.demo.com';
}
</script>
How about doing this:
<a href="#" onclick="redirect(); return false;">
demo
</a>
If you want the page to redirect to demo.html
when the user clicks a link, dare I suggest you use the universal, crossbrowser <a href="demo.html">demo</a>
?
Try:
window.location.href = 'http://www.demo.com';
in the function.
Try:
window.event.returnValue = false; document.location.href='http://www.demo.com';
精彩评论