Internet Explorer's problem with HREF's bug issues _ experience Exchange

Source: Internet
Author: User
Tags reset
Copy Code code as follows:

<div id= "Test" >
<a href= "#" > Test </a>
</div>
<div id= "Result" ></div>

<script type= "Text/javascript" >
(function () {
var test = document.getElementById (' test ');
alert (test.innerhtml);

var result = document.getElementById (' result ');
result.innerhtml = test.innerhtml;
Alert (result.innerhtml)
})();
</script>

As a result, the href value of the A element in the result.innerhtml of the second pop-up in the IE6 and IE7 browsers became an absolute path.
In fact, people have encountered these problems early (thank Yuber for the information):
  • getattribute ("HREF") is always absolute
  • "getattribute href bug"
    In the above article has already mentioned the processing scheme, is uses the getattribute (' href ', 2) method under IE. Microsoft extended the second parameter to this method, which can be set to 0, 1, 2, and if set to 2, returns the original value of the property.
    The script corrections are:
    Copy Code code as follows:

    (function () {
    var test = document.getElementById (' test ');
    alert (test.innerhtml);
    var result = document.getElementById (' result ');
    result.innerhtml = test.innerhtml;
    if (/* @cc_on!@*/0) {//if ie
    var links1 = test.getelementsbytagname (' a ');
    var links2 = result.getelementsbytagname (' a ');
    for (var i = 0, len = links1.length i < len; ++i) {
    Links2[i].href = Links1[i].getattribute (' href ', 2);
    }
    }
    alert (result.innerhtml);
    })();

    Searching for this issue also searched for an interesting BUG problem Hedger Wang discovered: When you reset the new href attribute value in IE, if the link text contains "http://" or "@", its InnerHTML will be displayed incorrectly and displayed as the set HR The EF attribute.
    Workaround (Shref is the new value for the href to set):
    Copy Code code as follows:

    Shref = ' http://www.hedgerwow.com ';
    var Ismsie =/* @cc_on!@*/false;
    if (Ismsie) {
    Shref = ' + shref; Add extra space before the new href
    };

    Details:Internet Explorer might reset Anchor ' s InnerHTML incorrectly when a new ' href ' is assigned

  • 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.