How do I create a modal that shows when your session expires

I am using the spring framework with various other dependancies, and I want my app to show a modal on the screen as soon as your session expired, instead of the built in redirect user back to login page if they try and make a request to the server. I would like to stay away from any frontend frameworks and stick to plain JavaScript or jquery. Any help you be appreciated! For example, when you are inactive on AWS for a certain amount of time, it shows a pop up on the page and makes you login again to continue.

Source: Ask Javascript Questions