Link to home
Start Free TrialLog in
Avatar of brgdotnet
brgdotnetFlag for United States of America

asked on

How to check for the existence of a function before I call it. Trying to avoid the object not found error message.

I am using some JQuery functions that are accessible on the web. For example : ajax.aspnetcdn.com

My web application runs on an Intranet. However I am accessing the plugins that are located on the Internet.
Everything works great, however if the website becomes disconnected from the Internet, the JQuery functions at aspnetcdn.com will not be found. In that event an exception will be thrown in my call to the JQuery code, and I will get a "object not found" error message for the function being called. So using JQuery or Java Script how can I check if the function in not defined before attempting to call it?
ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brgdotnet

ASKER

My longterm plan is to just download the cdn code locally. For now though I need more help on how to catch the exception so that I do not get the error message "Error: jQuery' is undefined. I am not passing in a variable into my function, and so I don't think
if (typeof jQuery.foo == 'undefined') {
will work in this situation. Here is my specific code. below. The exception will be thrown at line 2 below. Can someone help me out some more so that I can prevent the JQuery is undefined message from being displayed.

<script src=”http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.js”  type=”text/javascript”></script>

<script src=”http://ajax.aspnetcdn.com/ajax/jquery.ui.js”  type=”text/javascript”></script>
<script src=”http://ajax.aspnetcdn.com/ajax/jjquery.ui/1.8.16/themes/humanity/jquery-ui.css.js”    rel=”stylesheet”  type=”text/css” />

1  <script type=”text/javascript”>
2  $(function() {
3     $(“[id$=myTetBox]”).datepicker({
4   changeMonth: true,
5   changeYear: true
6});
7});
</script>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial