Ljopata
Ljopata

Reputation: 3

Go back browser button action

in my project I have included an additional go back button which code is:

<div class="button_1"><p><a href="test.php?action=delete&id=<?php echo $values["item_id"];?>" class="button-link">Go back</a></div>

Is it possible that the browsers go back button performs (via javascript or any other programming language) the same action so that I don't need to add an additional go back button to my project?

Thanks upfront for the support!!!

Upvotes: 0

Views: 327

Answers (2)

Umar Ahmed
Umar Ahmed

Reputation: 79

You can do it with window.history.back()

<button onclick="window.history.back();">Go Back</button>

Also you can window.history.forward() to go forward

Note: This function will work until you have a history in browser for the current tab

Upvotes: 0

AbsoluteBeginner
AbsoluteBeginner

Reputation: 2255

You can do this (Javascript):

document.getElementById('go-back').addEventListener('click', () => {
  history.back();
});
<button id="go-back">Go back</button>

Upvotes: 1

Related Questions