简体   繁体   中英

Back button jquery to previous page after current page has been reloaded

I need a way to go back to a previous page after the current page has been reloaded.

At the moment if I use my simple history -1 on the page that has been reloaded in jQuery it will send me back to the same (reloaded)page as is only expected.

Is there a way to identify that the page is the same page and therefore ignore it as a relevant option to go back to?

Here is the code I am using at the moment:

  $(document).ready(function(){ $('a.back-link').click(function(){ parent.history.back(); return false; }); }); 

Thanks,

Aidan

You could always use document.referrer to get the address of the page that originally referred you to your current page (location.reload() should not affect the referrer variable)

location.href = document.referrer;

A working example can be found here http://iamdevelop.in/referrer

Using your history.go(-1) , you can simply specify a different number to go a different number of pages.

Try using:

window.history.go(-2);

This should then skip that 1 back page which is the same and go back to the page before that.

Source

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