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.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

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