TransWikia.com

Go back browser button action

Stack Overflow Asked by Ljopata on February 11, 2021

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!!!

2 Answers

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

Answered by Umar Ahmed on February 11, 2021

You can do this (Javascript):

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

Answered by AbsoluteBeginner on February 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP