JQUERY TAB SWITCHING ACCORDING TO QUERY STRING VALUE

28 Sep

As we all know about jquery tabs and tab switching.Here i would like to share the code for  jquery tab switching according to some query string values. 

 

Let “tabid” be the query string . The function getQuerystring() is used to get the value of the query string “tabid”.According to that value we can switch the jquery tabs using

$(‘#tabs’).tabs(‘select‘, inx)  Where inx is the query string value

The code is :

<script type=”text/javascript“>
$(document).ready(function() {
var inx = getQuerystring(“tabid“);
if (isNaN(inx))
inx = 2;
$(‘#tabs‘).tabs();
$(‘#tabs’).tabs(‘select‘, inx); 

});

function getQuerystring(key, default_) {
if (default_ == null) default_ = “”;
key = key.replace(/[\[]/, “\\\[“).replace(/[\]]/, “\\\]”);
var regex = new RegExp(“[\\?&]” + key + “=([^&#]*)”);
var qs = regex.exec(window.location.href);
if (qs == null)
return default_;
else
return qs[1];
}
</script>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: