aidanjporter
aidanjporter

Reputation: 41

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

Upvotes: 0

Views: 4663

Answers (2)

James Hunt
James Hunt

Reputation: 2528

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

Upvotes: 2

bladeedg
bladeedg

Reputation: 61

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

Upvotes: 0

Related Questions