Reload page with different anchor

不羁岁月 提交于 2019-12-22 07:09:01

问题


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:


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>


来源:https://stackoverflow.com/questions/13770741/reload-page-with-different-anchor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!