3

I want to use javascript 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';

Andy
  • 7,646
  • 8
  • 46
  • 69

4 Answers4

1

A cleaner way:

window.location.hash = 'tabs-4';
window.location.reload();
Kay
  • 91
  • 1
  • 8
0

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

window.location.href = window.location.href + '#tabs-4';
Andy
  • 7,646
  • 8
  • 46
  • 69
0

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

Jonathan Lafleur
  • 493
  • 5
  • 25
0

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?

Community
  • 1
  • 1
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186
  • I want to reload the page from within a function if certain conditions are met. I can't just use a link. – Andy Feb 18 '11 at 18:08
  • but you can generate link on the basic of your condition. if(condition 1 ){ when you want to redirect page and switch to tab 1 link=link+"?tab=1" } – Vivek Goel Feb 18 '11 at 18:11