Friday, May 9, 2014

Javascript set location then hard refresh current page and set scroll position to top

I am using tabs in my page, by clicking on a link i need to open next tab in that same window, only by setting a href it is not happening. URL got changed as per #name but 2nd tab is not opening. To get rid of this problem i used following code to hard refresh the page with the new url.

<a onclick="window.scrollTo(0,0);window.location.assign('/page/subpage/#tab2');location.reload(true);" style="cursor:pointer">GO</a>

Here i am first set the current page's scroll position to top, then assign new url after that reload the page. by this way it is opening 2nd tab in the same page but it needs a refresh.

If you have any other idea please share with me.

No comments:

Post a Comment