Make a preventBack function not work on a certain url

I’m making a webpage to learn a bit of programming, this is my very first one, so I’m really new to this. I have a preventBack function that I’ve found on here, it works great, but I want a certain page (specifically the name is restart.html) not be affected by this script. I have been searching for some time and tried different solutions and implementations to the code but as I’m new to this, nothing has worked as I wanted to.

This is the function:

function preventBack() {
            window.history.forward();
        }
        setTimeout("preventBack()", 0);
        window.onunload = function () { null };

This is written in page1.html (for example), and it affects page2.html (because of the window.history.forward, if I’m not mistaken). I don’t really care where it is written, or even if the whole script changes, but I just want it to change behaviour so if you’ve clicked the restart button by mistake, you can just go back to the previous page and continue. I’ve tried it with if and else, also changing the number for the timeout, but it doesn’t work as I want it to.