Browsers provide load events for <script>
and <img>
tags. Is there a way to detect whether a request to a element has completed?
Specifically, I'm wishing to detect when a <link>
'd stylesheet has been loaded.
Unfortunately, I think using a sentinel style and detecting load from a computedStyle
isn't workable in my situation.
A URI — short for “Uniform Resource Identifier” — is a sequence of characters that distinguishes one resource from another. For example, foo://example.com:8042/over/there?name=ferret#nose is a URI containing a scheme name, authority, path, query and fragment. A URI does not need to contain all these components.
Referer: This optional header field allows the client to specify, for the server's benefit, the address ( URI ) of the document (or element within the document) from which the URI in the request was obtained.
The target of an HTTP request is called a "resource", whose nature isn't defined further; it can be a document, a photo, or anything else. Each resource is identified by a Uniform Resource Identifier (URI) used throughout HTTP for identifying resources.
To find the project's service relative URI, look at the Create a REST service page. The service relative URI is also shown on the REST Resource URI Editor page.
There may be a simpler way to do it, but this worked for me.
Make sure your <link>
tag has a title
attribute:
<link title="myStyles" rel="stylesheet" href="style.css" />
Then use a function like this to check for the presence of a style within a particular styleseet:
function linkLoaded(linkTitle, checkStyle)
{
for (var ix=0; ix<document.styleSheets.length; ix++) {
try {
if (document.styleSheets[ix].title == linkTitle) {
var mySheet=document.styleSheets[ix];
var myRules = mySheet.cssRules? mySheet.cssRules: mySheet.rules
for (var jx=0; jx<myRules.length; jx++) {
var thisSelector = myRules[jx].selectorText.toLowerCase();
if (thisSelector.substring(0, checkStyle.length) == checkStyle) {
alert("Found style!");
return;
}
}
}
}
catch (err) {}
}
alert("Not loaded!");
return;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With