0

I'm trying to open another html file or url various ways but non of them is working.

location.href = 'new_url';
location.replace('https://www.javascripttutorial.net/');
location.assign('https://www.javascripttutorial.net/');

So, I have a function when body loads it checks if cookies 'username' and 'password' are empty or are missing. That trigers an alert and then after I click on OK button on alert popup it should redirect but it doesn't.

Alert pops up so code works but when I press blue OK button it doesn't redirect

Help please?

Part of my JS code that i have problems with

    function check_cookie(){
     if ((getCookie('username') == null) || (getCookie('password') == null) || (getCookie('username') == "") || (getCookie('password') == "")){
        alert('Session Expired!');
        location.assign("https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage");
        return ;
  }
dopek
  • 1
  • 1
  • 2
    You should never have a `password` cookie. That's a terrible idea from a security perspective. – Taplar Sep 01 '20 at 13:38
  • @Taplar thanks for advise. I's still learning. What should i use instead? – dopek Sep 01 '20 at 13:54
  • Typically a cookie would save an authorization token, that the server generates for the duration of a session. And the client passes that on future requests so the server validates who they are. This way the credentials are not potentially exposed to anyone else that uses the same machine. – Taplar Sep 01 '20 at 13:55
  • What should you use in order to do what exactly? – Jeremy Thille Sep 01 '20 at 13:55
  • Jeremy - What should i use instead of cookies to store username, password... for a day? – dopek Sep 01 '20 at 14:16

1 Answers1

0

I have in my js code browser back button blockade and i deleted the following part.

window.onpopstate = function () { 
    history.go(1); 
}; 
dopek
  • 1
  • 1
  • i needed that function because I needed to detect when a screen was closed, that was just stupid from me, because i thought code didn't work ok, but actually I needed to do a hard reset on site (CTRL+SHIFT+R) – dopek Sep 01 '20 at 14:59