1,onload Events
Copy Code code as follows:
<! DOCTYPE html>
<HTML>
<HEAD>
<meta charset= "Utf-8"/>
<title>link Element onload</title>
<link type= "Text/css" rel= "stylesheet" href= "Http://i3.sinaimg.cn/rny/webface/login/css/login101021_min.css" onload= "alert (this)"/>
</HEAD>
<BODY>
</BODY>
</HTML>
IE6/7:
IE8/9:
Opera:
That is, Ie6/7/8/9/opera support the OnLoad event, Firefox/safari/chrome not supported.
Note: Create link tag with JS and add it to head, as above.
2,onreadystatechange Events
Copy Code code as follows:
<! DOCTYPE html>
<HTML>
<HEAD>
<meta charset= "Utf-8"/>
<title>link Element onreadystatechange</title>
<link type= "Text/css" rel= "stylesheet" href= "Http://i3.sinaimg.cn/rny/webface/login/css/login101021_min.css" Onreadystatechange= "alert (this)"/>
</HEAD>
<BODY>
</BODY>
</HTML>
IE6/7/8/9 was shot two times and no other browsers were playing. Indicates that only IE supports the onreadystatechange event of the link element. Pop up two times respectively is readystate for Loading,complete state. ReadyState can be used to determine loading conditions. We then use JS dynamic Create a LINK element to try,
Copy Code code as follows:
<! DOCTYPE html>
<HTML>
<HEAD>
<meta charset= "Utf-8"/>
<title>link Element onreadystatechange</title>
</HEAD>
<BODY>
<script>
function Createel (type, attrs) {
var el = document.createelement (type),
attr
For (attr in attrs) {
if (Attrs.hasownproperty (attr)) {
El.setattribute (attr, attrs[attr]);
}
}
Return el;
}
var link = createel (' link ', {
HREF: ' Http://i3.sinaimg.cn/rny/webface/login/css/login101021_min.css ',
Rel: ' stylesheet ',
Type: ' Text/css '
});
Link.onreadystatechange = function () {
Alert (This)
}
document.getElementsByTagName (' head ') [0].appendchild (link);
</script>
</BODY>
</HTML>
The Ie6/7/8/9 still pops up 2 times. Firefox/safari/chrome still hasn't played. Seems to be all right, but the magic is this time in opera popped out once, explain opera support dynamically create link element when the onReadyStateChange event.
Related:
Https://developer.mozilla.org/en/HTML/Element/link
Http://msdn.microsoft.com/en-us/library/ms535848%28v=VS.85%29.aspx
Http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html