Onclick JavaScript to Make Browser Go Back to Previous Page

Onclick javascript to make browser go back to previous page?

Add this in your input element

<input
action="action"
onclick="window.history.go(-1); return false;"
type="submit"
value="Cancel"
/>

Make browser back button show login page without error div

The thing is that when you press back the browser doesn't always reload the page, that's the reason of the logging still showing the error, so what you need is to force the page to reload. Here you have a link to the solution that im giving you, hope it works How to force reloading a page when using browser back button?

Edit:

Answering to your comment, yes, it should be placed in the js file, something like this should do the trick

var perfEntries = performance.getEntriesByType("navigation");  

(function(){
if (perfEntries[0].type === "back_forward") {
location.reload(true);
}
}());

This is a function that doesn't require to be called, the function calls itself when the JS file is loaded

Going back to previous page using javascript

According to this all major browsers are supported

How Do I go back to my html page without losing the index of it?

You need to save the state in a storage, for example a sessionStorage.
You can handle it with the onload Event.

You need to save the state in the storage when the button is clicked to show the image. And when the page reloads, check if the button is clicked, if so then show the container else don't show.

const showImage = () => {
sessionStorage.setItem('showImage', 'true');
document.getElementById("first").style.display ='block';
}

function myFunction() {
if (sessionStorage.getItem('showImage') === 'true') {
document.getElementById("first").style.display ='block';
sessionStorage.removeItem('showImage');
}
}

on the body tag add this:

<body onload="myFunction()">

For example:
https://jsfiddle.net/dn09ysa1/



Related Topics



Leave a reply



Submit