I'm an art student and currently working on an interactive art-piece, which also is a website. The website will be shown in an art exhibit. Now, here's the problem:
When show in the exhibition I'm scared of someone interacting with the site and closing the browser window. I need my website to open again when closed so I'm sure it's going to be accessible for the whole duration of the exhibition. Is there a way I can get the site to open again with JavaScript?
I'm pretty new to coding, but I was thinking maybe Replay/onUnload ?
Another side note is that the site will run locally without any internet access, so an offline solution would be preferred, but I'm honestly happy for any help I can get.
JavaScript in a web page cannot prevent people from closing the browser or leaving the site. If it could then you would find a lot of sites dedicated to displaying adverts and preventing people from leaving.
You should look at handling this outside the page.
Typically this is achieved by setting up a browser in Kiosk mode and configuring the operating system to log in and run the browser automatically while also not providing options to run other applications.
The specifics of how you do that depend on your choice of browser and operating system and there are quite a lot of steps. A quick web search turns up this guide to doing it with Ubuntu and Chromium which looks like a sensible option.
There are quite a lot of steps to set up everything to run automatically, but the core of it is to run the browser with:
chromium-browser \
--noerrdialogs \
--disable-infobars \
--no-first-run \
--start-maximized \
--kiosk https://localhost/ \
https://localhost/
That limits the ability of the user to close the browser, but it is still possible with keyboard shortcuts. If your work doesn't require the user to type anything then you can avoid giving them a keyboard. You should configure the system to restart the browser when closed for safety though.