简体   繁体   English

刷新后如何保持在同一页面上? 栏杆

[英]How to stay on same page after refreshing? rails

I am having few links in a page which redirects to different pages. 我在页面中的链接很少,它重定向到其他页面。 If I click on 3rd link suppose and a page is displayed. 如果我单击第三个链接,则会显示一个页面。 Now if I refresh the page it is redirecting to the first link. 现在,如果刷新页面,它将重定向到第一个链接。

But according to my requirement it should be in the same page ie on which link I clicked. 但是根据我的要求,它应该在同一页面上,即我单击的链接。 Can anyone tell me how achieve this functionality. 谁能告诉我如何实现此功能。

Here is the code: 这是代码:

<ul>
  <li><a href="#tabs-1">link-1</a></li>
  <li><a href="#tabs-2">link-2</a></li>
  <li><a href="#tabs-3">link-3</a></li>
</ul>

now if I click on link-3 and I am on link-3 page. 现在,如果我单击链接3并且我在链接3页面上。 now if I refresh the page I should be in the link-3 page. 现在,如果刷新页面,则应该位于链接3页面中。 Instead I am redirected to link-1 on page refresh. 相反,我在页面刷新时被重定向到link-1。

Since it seems like you're using jqueryUI tabs, you'll need to update the address bar after the activation event, so that the tab#id will appear over there: 由于您似乎正在使用jqueryUI选项卡,因此您需要在激活事件之后更新地址栏,以便tab#id出现在该位置:

$( ".selector" ).tabs({
  activate: function(event,ui) {
    var anchor = $(event.target).attr("id");
    location.hash = anchor; //this will add #id to your url, which upon refresh will trigger the jquery tab selection event
  }
}); 

Only way I can see this is possible is if you instead of refreshing the page manually by pressing F5 or similar actually have a meta refresh in page 3 which instructs your browser to automatically refresh and redirect after a given time amount. 我唯一能看到的方法是,如果您不是通过按F5或类似的方法手动刷新页面,而是实际上在页面3中进行了元刷新,它指示浏览器在给定的时间量后自动刷新和重定向。 Have you written the page linked to by link3 yourself? 您是否自己编写了通过link3链接到的页面? If not, can you check the headers in page 3 for something like <meta http-equiv="refresh" content="5; url=http://example.com/"> ? 如果不是,您是否可以在第3页的标题中查找<meta http-equiv="refresh" content="5; url=http://example.com/">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM