Is it possible to do a js script that will make the page return “403 forbidden” error when trying to visit?
In Backend or front end?
what’s the difference i am newbie dev :V
Without some basic info like what your app does it is impossible to know how to fix it. One assumes that it is a web site but might not be, it could be an API or a Discord Bot or something else. Have you used a server? Does it have a name? Is your project public?
It’s a static webpage. I was just wondering if there is a way to make a JS script to return a 403 error.
I’m probably not the person who can ultimately answer this but I’m trying to explain there may not be enough data to go on. It is a static page? Meaning the JS is running on the browser?
What generates the need to generate such an error? I suspect it is the lack of information that is limiting the responses.
I just want to generate a 403 error using a simple js code .-.
You will need to use server side code to send status codes.
MDN has a lot of good tutorials for a beginner. This one goes into the difference between front- and back-end:
As Tleylan said, the solution will be dependent on the context it is used. You would need to look into the response interface to generate a response with the needed status code, and then you can do what you want with it.
If you want to send it somewhere else, or do something else with it, you would propably have to use something else than a service worker. It may even be impossible depending on your use case.