开发者

Use Javascript to reload the page and specify a jquery tab

开发者 https://www.devze.com 2023-02-12 03:25 出处:网络
I want to use j开发者_开发百科avascript to reload a page.I can\'t just use window.location.reload(); as I\'m using jquery tabs and want to specify a tab to be selected after the reload. Is setting win

I want to use j开发者_开发百科avascript to reload a page. I can't just use window.location.reload(); as I'm using jquery tabs and want to specify a tab to be selected after the reload. Is setting window.location.href the best way to do this?

i.e. window.location.href = window.location.href + '#tabs-4';


A cleaner way:

window.location.hash = 'tabs-4';
window.location.reload();


All you have to do is to pass a var in the url (post) than with your javascript retreive it and select the tab associated to the var


you can have variable in redirect link like index.html?tab=4 and than check it's value in javascript.

function get(name){

if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search)) return decodeURIComponent(name[1]); } you can use this code to get a value. like

selec=get('tab');
 $tabs.tabs('select', selec);

to switch to a tab. See this link to get more details about

How to get "GET" request parameters in JavaScript?


As Brandon Joyce commented, my original code was probably best:

window.location.href = window.location.href + '#tabs-4';
0

精彩评论

暂无评论...
验证码 换一张
取 消