简体   繁体   中英

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. now if I refresh the page I should be in the link-3 page. Instead I am redirected to link-1 on page refresh.

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:

$( ".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. Have you written the page linked to by link3 yourself? If not, can you check the headers in page 3 for something like <meta http-equiv="refresh" content="5; url=http://example.com/"> ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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