2 Replies Latest reply on Oct 18, 2016 8:40 AM by thales

    Detect user login status through HTML widget

    thales

      I have created an HTML button that links to the create idea page. I would like to make that button visible/hidden based upon whether a user is logged in or not. Is there a way to detect the login status of a user through HTML?

        • Re: Detect user login status through HTML widget
          mcollinge

          It doesn't look like this is possible through CSS, or plain HTML. You'd have to resort to JavaScript/jQuery, at which point it's really easy (_jive_current_user contains all the user info you'll need).

            • Re: Detect user login status through HTML widget
              thales

              Thanks Matt Collinge! That got me a lot closer. I was able to use _jive_current_user.anonymous to detect if a user was logged in or not. I am still working on getting the button working properly, but the example below will change the text and add the username based upon login status:

               

              <!DOCTYPE html>
              <p id="btn"></p>
              
              <script>
                var text;
              
              
                // If the user is not logged in
              
              
                if (window.parent._jive_current_user.anonymous) {
                    text = "Not Logged In: " + window.parent._jive_current_user.username;
                    
                // If the letter is anything else
                } else {
                    text = "Logged In: " + window.parent._jive_current_user.username;
                }
              document.getElementById("btn").innerHTML = text;
              </script>