I have an asp.net mvc partial which contains a jquery ui tab control, marked up like so:
<div id="admin_tabs" class="tabs_admin">
<div id="admin_header">
<ul>
<span class="admin_title">Administration</span>
<li style="float:right; display:inline"><a href="#maint_tab">Maintenance</a></li>
<li style="float:right; display:inline"><a href="#log_tab">Logs</a></li>
<li style="float:right; display:inline"><a href="#groups_tab">Groups</a></li>
<li style="float:right; display:inline"><a href="#users_tab">Users</a></li>
<li style="float:right; display:inline"><a href="#app_settings_tab">Application Settings</a></li>
</ul>
</div>
<div id="app_settings_tab" class="tab_admin">
</div>
<div id="users_tab" class="tab_admin">
</div>
<div id="groups_tab" class="tab_admin">
</div>
<div id="log_tab" class="tab_admin">
</div>
<div id="maint_tab" class="tab_admin">
</div>
</div>
<script type="text/javascript">
$("#admin_tabs").tabs({ selected: 4 });
</script>
This works fine. But I would like the application to remember what tab was last open when the page is refreshed, so I changed my JavaScript to
$("#admin_tabs").tabs({selected: 4, cookie: {}});
This immediately causes a javascript error and the tabs stop working. According to the chrome console, the error is Uncaught TypeError: Cannot call method 'apply' of undefined occuring on Line 7520 of jquery-ui.js. I have included the cookie plugin prior to including jquery ui, but to no effect. The code which is breaking is
_cookie: function() {
var cookie = this.cookie ||
( this.cookie = this.options.cookie.name || "ui-tabs-" + getNextListId() );
return $.cookie.apply( null, [ cookie ].concat( $.makeArray( arguments ) ) );
It appears to break because there is no cookie set when I first load the page. Any clues as to why that might be, or any other way to fix the problem?
I figured out what was wrong. For some reason, the cookie plugin wasn’t being included correctly. I had it in an external script, but moving it into the body of the document fixed the problem.