block access to a javascript-only page

Asked

Viewed 46 times

0

I have an index.html file, which after login is directed to a page called home.html

there is some way to block direct access to this javascript-only home.html?

  • It is not possible. Any access lock performed in the client code can be bypassed by the user using the development tools included in the browser, make this access lock on the server.

1 answer

2


You can make a control using sessionStorage.

In index.html:

sessionStorage.setItem('usuarioLogado', '1');

In home.html:

var usuarioLogado = sessionStorage.getItem('usuarioLogado');

if (!usuarioLogado) {
    window.location = "ENDEREÇO PARA ONDE VOCÊ QUER REDIRECIONAR"
}
  • Note: [sessionStorage][https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage] is cleaned after closing the browser. If you wish to dock save after that, you must use [localStorage][https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage].

  • managed using this + the new date of javascript.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.