Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created January 7, 2010 14:03
Show Gist options
  • Save aheckmann/271241 to your computer and use it in GitHub Desktop.
Save aheckmann/271241 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Detecting Stylesheet Load Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function () {
var css = document.createElement('link');
css.type = 'text/css';
css.rel = 'stylesheet';
css.href =
"http://groups.google.com/groups/style.css?ig=1&stock=1&av=4&hl=en&v=639";
if ( jQuery.browser.msie || jQuery.browser.opera ) {
jQuery(css).bind('load', function () {
jQuery('body').text('Cross-domain load in IE or Opera!');
});
} else {
var num = -1;
(function sheetLoaded () {
try {
num++;
css.sheet.cssRules;
} catch (e) {
// Gecko (Firefox) throws NS_ERROR_DOM_INVALID_ACCESS_ERR
// exceptions while the link is loading. Once complete, it
// throws NS_ERROR_DOM_SECURITY_ERR.
// Adapted from Julian Aubourg's great solution:
// http://github.com/jaubourg/jquery/blob/master/src/transports/css.js
if ( "NS_ERROR_DOM_SECURITY_ERR" != e.name ) {
setTimeout(sheetLoaded, 50);
return;
}
}
// if we got here the stylesheet is loaded
jQuery('body').text('Cross-domain load! Number of tries: ' + num);
})();
}
jQuery('head').append(css);
});
</script>
</head>
<body>
Loading Stylesheet...
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment