respect the session expiration on all pages

To get your functionality to work, you will need to place your code onto a public JS-File and not on the page itself. Or you do it on the MASTER-PAGE, but doing it on MASTER-PAGE, it would expect that you have your header on every of your pages.

To get more info about the functionality you are trying to achieve, you will find here…