Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error traping on Javascript call

Status
Not open for further replies.

neofactor

Technical User
Jul 30, 2000
194
US
Is it possible in Javascript to check is a file exists first.. then load the .js file.. if not... show an alternate message like : Content not available at this time.... or Server down.. ect.


so if the server you are calling the javascript include happens to go offline... people do not see the error:

<script language=&quot;JavaScript&quot; src=&quot;
Perhaps I could wrap the function with an If statement and say onError... had trouble.

What would I say to check it though?


Thanks for any help!

David David McIntosh

Have a nice day!
 
sure!

supposing you have a function &quot;foo();&quot; in your js include
Code:
<script language=&quot;JavaScript&quot; src=&quot;[URL unfurl="true"]http://unstableserver.com/javascriptfile.js&quot;></script>[/URL]

you could use this after the include statement:
[tt]
try {
foo();
}
catch(e) {
alert(&quot;Error&quot;);
}
[/tt]
if all is well, foo() will be called, else the alert() will be shown.


=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top