Reload page with different anchor

2019-05-07 04:34发布

Just got stuck with one problem. I have a page with Jquery UI tabs. Each tab can be accessed from different page by adding a hash tag to the link and it loads the page with the tab that I need. However, I also need to access different tabs within the same page. What I came up with is to add target="_parent" to the link with hash tag:

<a href="pictures.htm#tab2" target="_parent">

and it does what I need but only in IE. It reloads the page with different hash tag but for some reason Chrome and Firefox load the same tab every time. What I need is to create a javascript function for the link which will fully reload the page with different hash tag.

I came up with this code:

function gototab(reload)
   {
    window.location.href = 'pictures.htm#tab2';
    window.location.reload(true);
   }

<a href="pictures.htm#tab2" onclick="gototab();">open tab 2</a>

I feel like I almost closed it but something is wrong with my script. Can anybody help me to solve it?

Thanks!

1条回答
Ridiculous、
2楼-- · 2019-05-07 05:20

You can do this:

function gototab(reload)
   {
    window.location.hash = '#tab2';
    window.location.reload(true);
   }

<a href="pictures.htm#tab2" onclick="gototab();">open tab 2</a>
查看更多
登录 后发表回答