BUG problem of href under IE_Experience exchange

WBOY
Release: 2016-05-16 12:04:03
Original
1607 people have browsed it
Copy Code The code is as follows:






As a result, it will pop up for the second time in IE6 and IE7 browsers The href value of the A element in result.innerHTML becomes an absolute path.
In fact, our ancestors have encountered these problems long ago (thanks to Uncle Yu for the information):
  • 《getAttribute(”HREF”) is always absolute》
  • 《getAttribute href bug》
    The solution has been mentioned in the above article, which is to use the getAttribute('href', 2) method under IE. Microsoft has extended this method with a second parameter that can be set to 0, 1, or 2. If set to 2, the original value of the property is returned.
    The script is corrected to:
    Copy code The code is 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 links2[i].href = links1[i].getAttribute('href', 2); }
    }
    alert(result.innerHTML);
    })();

    While searching for this problem, I also searched for one discovered by Hedger Wang Interesting BUG: When resetting a new href attribute value in IE, if the link text contains "http://" or "@", its innerHTML will be displayed incorrectly and will display as the set href attribute.
    Solution (sHref is the new value of href to be set):
    Copy code The code is as follows:

    sHref = 'http://www.hedgerwow.com';
    var isMSIE = /*@cc_on!@*/false;
    if( isMSIE ){
    sHref = ' ' sHref; //add extra space before the new href
    };

    详细:《Internet Explorer might reset Anchor's innerHTML incorrectly when a new “href” is assigned》

  • Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!