June 27, 2011

Cancel tab selection in jQuery

Question by Mike

I have created some tool that has 4 pages.
I order to navigate between the pages I am using jQuery “tabs” (in the header of each page).

Is there a way to cancel the clicking operation after some tabs was clicked?
For example: If the page wasn’t saved the user will get a propper warning: “click YES in order to continue without saving or click NO in order to stay in the unsaved page”.

Thanks in advance.
Mike

Answer by Starx

In order to cancel or abort the tab’s ajax request do something like this

$('#tabs').tabs({
    ajaxOptions: {
        timeout: 10000,
        error: function() {
            // If error occurs while trying to load a page via AJAX, abort the tabs
            $('#tabs').tabs('abort');
        }
    }
});

For more information go here.

...

Please fill the form - I will response as fast as I can!