0

I created a confirm alert for throwing a message if a particular user's password is about to expired and request them to change their password.

I created a function for this in the header.
If user successfully logs in, they will be directed to the home page (where I call the function - index.jsp).
The confirm alert will show up (as expected) when user successfully login.
Then, each time user clicks the Home menu (index.jsp page), the confirm alert will show up again.

How to make it to show up only once?
I want to make it appear just when user successfully login to the page.

Anyone can help? Would appreciate it so much.

This is in the header.jsp:

function pwdAlert(){
  <%if(!headerexpDay.equals("") && Integer.parseInt(headerexpDay) <= 10 ){%>
    var expDay = "<%=headerexpDay%>";

    if(confirm("Your login password will be expired in "+expDay+" day(s). Do you want to change password?")){
      document.frmHeader.method = "POST";
      document.frmHeader.action= "<%=request.getContextPath()%>/admin/frmChangePassword.jsp";
      document.frmHeader.target= "_self";
      document.frmHeader.submit();
    }
  <%}%>
}

And this is in the index.jsp (home page) where I call the function.

<SCRIPT>
  document.onreadystatechange = function () {
    if (document.readyState === "complete") {
      pwdAlert();
    }
  } 
</SCRIPT>
Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
oscarito
  • 35
  • 7
  • Do you mean you don't want the message showing again if the user elects *not* to change the password? I assume if they change their password immediately then that stops it showing again, but you don't say so clearly. – nnnnnn Mar 29 '17 at 01:59
  • Possible duplicate of http://stackoverflow.com/questions/24768067/display-alert-only-once – manian Mar 29 '17 at 02:00
  • @nnnnnn sorry my bad, i didn't state it clearly. It supposed not to show up again when user selects No in the confirm alert. – oscarito Mar 29 '17 at 02:02

1 Answers1

0

Make use of cookies, step can be described like bellow:

  1. Read the cookie variable (name: isIgnored as an example)
  2. If isIgnored === false, run your pwdAlert()
  3. Inside your pwdAlert, change your code of promt

    if(confirm("Your login password will be expired in "+expDay+" day(s). Do you want to change password?")){ 
        // Your own code here
    } else {   
        // Set the cookie variable: isIgnored = true 
    }
    
  4. This show how to use cookies: https://www.w3schools.com/js/js_cookies.asp

VinhNT
  • 1,091
  • 8
  • 13