hi,
i have this jquery page that is included in an html file and in that file i have a function with .dialog() i want to open a normal pop up if this dialog doesn't work.. i was wondering how ca i do this... will try() catch() work on this..?
appreciate replies , thanks in advance.

Yes, you can use try/catch but remember that this will only handle otherwise uncaught javascript errors. It won't handle socalled "silent failures" as can arise in jQuery which is, to a certain extent, error tolerant.

For example, if jQueryUI was not installed on the page, then try { $('#myDiv').dialog('open'); } would throw a catchable error. However, if jQueryUI was installed but #myDiv did not exist, then failure would be silent; you would need to test for this failure and throw your own error.

try {
  $dialog = $('#myDiv').dialog({ autoOpen:false });
  if ( $dialog.length == 0 ) {
    throw "Dialog not found";
  }
  else {
    $dialog.dialog('open');
  }
}
catch(e){
  window.open(.....);  
}

Whereas this is the most likely type of silent failure, there may be others. You will need to research and/or test rigorously to find out what they might be.

Airshow

thanks a lot Airshow..
so.. if a user includes this jquery file and for some reason (maybe because of other jquery files that may have been included) jquery dialog won't open , this pop-up will open? i was wondering how to create this situation so i can test it.. :-/

hi Airshow,

this is what i'm trying to do. there is a content on a web page if i click on a div i will get a jquery dialog and if it doesn't work a pop up will open. i want to open the content i clicked on of the 1st page inside that pop up. i have no idea how to do it. since i can't take data from the previous page to the next page..?

What you are trying to do is to write two mechanisms to achieve exactly the same end, with one mechanism acting as a fallback for the other.

This is not necessarily difficult but it does mean that you will end up writing and debugging (and subsequently maintaining) two sets of code (probably php, html and javascript) - one for the dialog and one for the popup window. With skill and care you should be able to make some of the code common to the two mechanisms but I can't conceive of code that would be 100% common.

Personally, I would consider my time better spent ensuring that all javascript/jQuery scripts/plugins are mutually compatible. Otherwise, you could end up needing fallback mechanisms for several facets of your application, not just this one.

I therefore suggest that you cut your losses with this approach and concentrate your effort on finding/writing/testing scripts that will work in each other's company.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.