Window.location problem

I am facing an unusual problem in ie6.

When I use window.location to redirect the page through javascript, it works fine in all browsers except ie6.

It works in ie 6 if I post exactly the same as below:

<a href="javascript:void(0);" onclick="javascript:window.location('http://www.demo.com');">demo</a>

but it does not work for the code below.

<a href="javascript:void(0);" onclick="javascript:redirect();>demo</a>
function redirect()
{
  window.location('http://www.demo.com');"
}

You can understand that the problem is here.

Thank.

Avinash

+1
source share
5 answers

The protocol is javascript:used only if you have Javascript code in the url. If you put it in an event handler, it will become a shortcut instead.

location , . href .

, , , .

<a href="javascript:void(0);" onclick="redirect();>demo</a>

<script type="text/javascript">
function redirect() {
  window.location.href = 'http://www.demo.com';
}
</script>
+7

:

<a href="#" onclick="redirect(); return false;">
  demo
</a>
+1

If you want the page to be redirected to demo.htmlwhen the user clicks the link, I dare to suggest you use a universal, crossbrowser <a href="demo.html">demo</a>?

+1
source

Try:

window.location.href = 'http://www.demo.com';

in function.

0
source

Try:

window.event.returnValue = false; document.location.href = 'HTTP://www.demo.com';

0
source

All Articles