Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use window.location.href to go 2 pages back and reload

Tags:

javascript

Is it possible to tell window.location.href to go back 2 pages in history and reload the page that is called?

i only managed to get it to work like this:

<script type="text/javascript">
window.location.href = "http://www.google.com/";
</script>

Everything else i try with the command history.back(-2) does not work in my case.

like image 905
Marcel Wasilewski Avatar asked Sep 04 '15 12:09

Marcel Wasilewski


People also ask

Does window location href reload the page?

location. reload() reloads the current page with POST data, while window. location. href='your url' does not include the POST data.

What does Window location href return?

The window.location.href property returns the URL of the current page.

Does window location href return a string?

The href property of the Location interface is a stringifier that returns a string containing the whole URL, and allows the href to be updated.

How do you pass POST data with Windows location href?

Using window. location. href it's not possible to send a POST request. What you have to do is to set up a form tag with data fields in it, set the action attribute of the form to the URL and the method attribute to POST, then call the submit method on the form tag.


3 Answers

Try this, it will take you two step back

 history.go(-2);

eg,

<a href="www.mypage.com" onclick="javascript:history.go(-2)"> Link </a>
like image 58
Dimag Kharab Avatar answered Nov 15 '22 14:11

Dimag Kharab


You should use history.back(2);, not history.back(-2);.

like image 45
Jazi Avatar answered Nov 15 '22 12:11

Jazi


you can use function history.go(-2) to move backward two pages previously and history.go(2) to move forward 2 page that you left after you back from 2 pages before

<script>
function goBack() {
  window.history.go(-2);
}
</script>
like image 42
bayu Avatar answered Nov 15 '22 13:11

bayu