Steve
Steve

Reputation: 8640

jQuery Mobile - handling JS errors on new page

I encountered a never ending "Loading" dialog when moving from one page to the next, because the next page had a JS error in it.

Is there a way to avoid the loading message and instead show an error message?

Edit: To clarify, I am looking for a solution that displays an error message to the user (like "We encountered a problem. Please contact the system administrator"). It would also be great to return to the previous page, so a user can continue to use the app. As it is right now, a JS error stops them cold in their tracks.

Upvotes: 0

Views: 740

Answers (1)

Ryan
Ryan

Reputation: 28247

It is possible to detect and react to page loads that failed using something like:

     $('#pagename').live('pageloadfailed', function () {
     alert('page load failed.');
     });

But a true Javascript error is handled at the browser level, and will stop execution when encountered.

Your best best would be to encapsulate the potential javscript problem in a try ... catch block and add some logic around it.

Upvotes: 1

Related Questions