Jump to content
  • Advertisement
Sign in to follow this  
Jaguar_Lee

[web] javascript loaded

This topic is 4236 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello all, I am finding ways to handle '<script src=xxxx.js>' javascript load fail. are there ways to find the fail, to avoid the fail and handle it when the fail appears. thank you.

Share this post


Link to post
Share on other sites
Advertisement
What do you mean load fail? Do you mean you want to know when the external script does not load and if you want an error handling system for that?

If that is case, I would do something like this:

MyExternalScript.js

var MyExternalScript = true;
// ...
// Rest of the script here
// ...


MyWebPage.html

<script type="text/javascript">
var MyExternalScript = false;
</script>

<script type="text/javascript" src="MyExternalScript.js"></script>

<script type="text/javascript">
if( !MyExternalScript ){
// variable not set to true, so script possibly failed to load
// Handle error here
}
</script>


Since there is no other way to check if an external file has been loaded, this is probably the only workaround. However, be sure to make the variable name as unique as possible, or it may get overwritten with another true value and you might not get the expected results.

Share this post


Link to post
Share on other sites
thank you for Verminox' reply.
for more, is it possible to load the external script again by the error handling system( javascript ) when the loading fail occur. you know <script> is a html tag,

Share this post


Link to post
Share on other sites
Using javascript,

document.write("<script type='text/javascript' src='MyExternalScript.js'>"+"</scr"+"ipt>")


The string is broken into parts because if it encounters the </script> tag directly the script will terminate.


Note: I don't see why you would need this though, if the external script didnt load the first time, it probably wouldn't load the next time either. And if your external script and your html page are on the same server, they should work simultaneously. It is very unlikely that your external file will fail to load once, and your html file will load, detect it, attempt to reload it and work again.

Share this post


Link to post
Share on other sites
why would there be a situation where the script didn't load? If you have the <script> tags in the <head> of the document they should load before the page finishes rendering.

Share this post


Link to post
Share on other sites
If the javascript fails to load regularly, you should debug and fix the load problem, NOT install some kind of kludgy work-around.

Mark

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!