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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to handle external application unavialability

Status
Not open for further replies.

palchuri

Programmer
Apr 22, 2005
17
US
<HTML>
<HEAD>
<TITLE>A document with SCRIPT</TITLE>
<META http-equiv="Content-Script-Type" content="text/tcl">
<SCRIPT type="text/javascript" src="</SCRIPT>
</HEAD>
<BODY>
<SCRIPT type="text/javascript">
if(isAppAvailable('code')){

// do something
}else{

// do something
}
</SCRIPT>
</BODY>
</HTML>


In this launcher.js is located on external application, which may not available some times. If the script is not available when I invoke isAppAvailable, getting JS error. Is there any way I can handle this situation so that user never see a JS error.

Thanks in advance.


Regards
Shri
 
Yes, you can test to see if a known function is present in the DOM.

Example launcher.js contains the following code:
Code:
function showVersion() {
  return "1.123v222";
}

You can then test (on the page) that this function is available using something like this:
Code:
function isAppAvailable() {
  return typeof showVersion === 'function';
}
if (isAppAvailable()) {
  // do something
} else {
  // handle the app not being available (yet)
}
Hope this makes some sense.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Put a try() catch() block around it. This assumes your users have a modern browser that supports this, of course (so not IE 5.5 or below).. For example:

Code:
try {
   if(isAppAvailable('code')) {
      ...
   }
}

catch(e) {
   alert('An error has occurred:\n\n' + e);
}

finally {
   // whatever here
}

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks guys for your help. I used try block because it is simple.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top