-1

iam working on a tampermonkey script (javascript), and i need a help about go back to the previouse page, i already tryed some codes but did not worked, the code used can go back to the previouse page but after loading the back again to the first page and a loop of back and foward is started please help i want only back to previouse page and stop the codes used before

history.back()

and

window.history.go(-1) 

and

if (history.length) {
    //There is history to go back to
    history.go(-1);
}
rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
timomo
  • 67
  • 1
  • 8
  • 1
    java is to javascript as ham is to hamster (i.e. completely and utterly unrelated). I fixed your tags for you. – rzwitserloot Aug 23 '21 at 00:22
  • Does this question help you? https://stackoverflow.com/questions/8067510/onclick-javascript-to-make-browser-go-back-to-previous-page – Pelicer Aug 23 '21 at 00:24
  • 1
    Does this answer your question? [Onclick javascript to make browser go back to previous page?](https://stackoverflow.com/questions/8067510/onclick-javascript-to-make-browser-go-back-to-previous-page) – Pelicer Aug 23 '21 at 00:25

1 Answers1

0
let overlayHTML = `
<button onclick="goBack()">Go Back</button>
`
let overlay = document.createElement("div");
    overlay.innerHTML = overlayHTML;
    document.body.appendChild(overlay);

function goBack() {
  window.history.back();
}

I am assuming you know how to make the beginning of the userscript

//@match   www.thewebsite.com

etc

LightLord
  • 61
  • 4