Use jquery cookie https://github.com/carhartl/jquery-cookie and then you can be sure the class will stay on page refresh.
Stores the id of the clicked element in the cookie and then uses that to add the class on refresh.
//Get cookie value and set active
var tab = $.cookie('active');
$('#' + tab).addClass('active');
//Set cookie active tab value on click
//Done this way to preserve after page refresh
$('.topTab').click(function (event) {
var clickedTab = event.target.id;
$.removeCookie('active', { path: '/' });
$( '.active' ).removeClass( 'active' );
$.cookie('active', clickedTab, { path: '/' });
});