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