So, basically I want to load an external file with JavaScript on page load. But want to do the same thing when users force to stop the browser loading process of a page that hasn't finished loading (for slow connections). Is this possible?
What if you loaded the script by default but cancelled the function on load?
Alternatively, if the JS is manipulating elements on the page, what if you used CSS classes? I.E a default 'not-loaded' class on your body element that the JS manipulates. Then have JS when loaded properly change the body class like 'loaded' and therefore that would respond to the JS in that circumstance?
@andy_unleash I'm confusing :p I want to trigger the same thing in two situations: Loaded, or Forced to Stop.
I don't want the external files (script or stylesheet) loaded by default. So basically I want to load JSON (for the example) only when the page is loaded. But, if the user stop the page loading because of the slow connection or something, it would also trigger the JSON to loading:
The logic is: If the page has successfully loaded, a Hopla! message will appear. If the page loading is stopped by force, a Hopla! message will appear too.
The main priority is that the function will triggered after the page successfully loaded.
A simple case: A loading animation layer that covered the whole page will appear before the page has been loaded, and will fade-out if the page has been loaded. But what if the page still does not loaded? If only I can make the layer invisible when users forcing to stop the browser loading, then that's what I need.
By the way, my main goal is to load the JSON on two situations that I wrote above, because this part is quite important, but too large to be loaded in the same time with others and it's likely will interfere with other loading processes.
It's OK. I will also try to find the way in other places as well. If any...
So, basically I want to load an external file with JavaScript on page load. But want to do the same thing when users force to stop the browser loading process of a page that hasn't finished loading (for slow connections). Is this possible?
Illustration:
What if you loaded the script by default but cancelled the function on load?
Alternatively, if the JS is manipulating elements on the page, what if you used CSS classes? I.E a default 'not-loaded' class on your body element that the JS manipulates. Then have JS when loaded properly change the body class like 'loaded' and therefore that would respond to the JS in that circumstance?
@andy_unleash I'm confusing :p I want to trigger the same thing in two situations: Loaded, or Forced to Stop.
I don't want the external files (script or stylesheet) loaded by default. So basically I want to load JSON (for the example) only when the page is loaded. But, if the user stop the page loading because of the slow connection or something, it would also trigger the JSON to loading:
The logic is: If the page has successfully loaded, a
Hopla!message will appear. If the page loading is stopped by force, aHopla!message will appear too.I may be wrong but why can't you just not use onload? Can't it just be a self executing function?
The main priority is that the function will triggered after the page successfully loaded.
A simple case: A loading animation layer that covered the whole page will appear before the page has been loaded, and will fade-out if the page has been loaded. But what if the page still does not loaded? If only I can make the layer invisible when users forcing to stop the browser loading, then that's what I need.
By the way, my main goal is to load the JSON on two situations that I wrote above, because this part is quite important, but too large to be loaded in the same time with others and it's likely will interfere with other loading processes. It's OK. I will also try to find the way in other places as well. If any...
Can't you just use a try catch block?
@JohnMotylJr: How? I don't know.
PS: I got an example of JavaScript event called
onerrorandonabortbut it's not working forwindow(as far as I'v tried).Nevermind, I read your above and I think your logic is just a little off. Your not wanting to load externals if something is forced to stop loading?
@JohnMotylJr: Contrarily. I want JavaScript to do something when the browser totally stop doing something.
I just find it difficult to describe and to exist.