Solution to failure of location. href of tag a in IE6

Source: Internet
Author: User

I met a location in IE6 today. href bug. in IE6, write href as javascript:; javascript: void (0); In tag a, and bind the onclick event to the tag, click and execute location. href implements page Jump, for example, the following code:

<A href = "javascitp:;" onclick = "toURL ()"> click to jump </a>

Or

<A href = "javascitp: void (0);" onclick = "toURL ()"> click to jump </a>

The code for the toURL function is as follows:

function toURL(){location.href = "http://js8.in";}

In this way, it can be used in non-IE6 browsers, but it cannot be redirected in IE6, and no error is reported. code after href, such as (alert (1);) is also executed.

Solution to location. href failure in IE6

In IE6, location. href is invalid because the href in tag a does not use javascript:; or javascript: void (0 );. The specific reason is unclear, but we can use href = "#" instead.

For example, the following code is normal in IE6:

<A href = http://www.js8.in/"###" onclick = "toURL ()"> normal redirect </a>

Another way is to set the href of tag a to "#" Through setAttribute in the toURL function, and then use location. href to redirect.

In addition, you can also solve the problem by getting the DOM node and binding the onclick event. For example, the following code:

var as = document.getElementsByTagName('a');for (var i=0;i<as.length;i++) {    as[i].onclick=function() {          window.location.href="http://www.js8.in";         return false;    }}
Conclusion

IE6-the nightmare of the front-end is still going on.
I really don't want to say anything about IE6. This station is no longer in support of IE6, And I hope IE6 will exit the historical stage as soon as possible.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.