16 Replies Latest reply on Jun 18, 2014 4:24 PM by ronanfeely

    Can anyone troubleshoot this JavaScript that won't work in IE?

    ronanfeely

      Hi there,

       

      At my wits end over this one.

       

      On my Overview page I have a HTML widget that contains a simple JavaScript that detects if a user is logged in.

       

      If they are not logged in the HTML widget displays a Register Now box and if the user is logged in the same widget now displays a Your Stuff type box.

       

      It works perfectly except in IE where it neither box appears unless you Ctrl+F5 the page. Sadly about 75% of our users still come using IE.

       

      Can anyone help? Pretty pretty please? Code below.

       

      Ronan.

       

      <div id="registered-output">

       

      <script type="text/javascript">

       

      window.onload = loadScript;

       

      function loadScript() {

       

      var currentuser = window.parent._jive_current_user.displayName; 

      var useremail = window.parent._jive_current_user.username; 

       

      if (currentuser == 'ANONYMOUS') {

      document.getElementById("registered-output").innerHTML = "<div class='register-container'><div class='register-header'><div class='register-header-holder'><p class='header-text'>Register</p></div><div class='register-toptext'><p class='titled'>Why join our community?</p></div></div><div class='register-ul'><ul class='register'><li class='register-li'>Learn through asking questions and getting answers</li><li class='register-li'>Share your expertise on issues, best practices, and experiences</li><li class='register-li'>Network with a global community of engineering professionals</li></ul></div><div class='register-join'><a href='https://mentor.jiveon.com/create-account.jspa'><img src='http://mentor.jiveon.com/resources/statics/16528/join-here-smaller.png'></a></div></div>";

      }

      else if (currentuser != 'ANONYMOUS') {

      document.getElementById("registered-output").innerHTML = "<div class='register-container-stuff'><div class='register-header'><div class='register-header-holder'><p class='header-text'>Personal Settings</p></div><div class='register-toptext'><p class='header'>Welcome " + currentuser + "</p></div></div><div class='register-ul-two'><table><tr><td><img src='/resources/statics/16528/content.png'></td><td> </td><td><a target=_new href='people/" + window.parent._jive_current_user.username + "/content');'>Your Content</a></td></tr><tr><td><img src='/resources/statics/16528/activity.png'></td><td> </td><td><a target=_new href='people/" + window.parent._jive_current_user.username + "/activity');'>Your Activity</a></td></tr><tr><td><img src='/resources/statics/16528/connections.png'></td><td> </td><td><a target=_new href='people/" + window.parent._jive_current_user.username + "/people');'>Your Connections</a></td></tr><tr><td><img src='/resources/statics/16528/places.png'></td><td> </td><td><a target=_new href='people/" + window.parent._jive_current_user.username + "/places');'>Your Places</a></td></tr><tr><td><img src='/resources/statics/16528/bookmarker.png'></td><td> </td><td><a target=_new href='people/" + window.parent._jive_current_user.username + "/bookmarks');'>Your Bookmarks</a></td></tr></table></div></div>";

      }

      }

       

      </script>

       

      </div>

        • Re: Can anyone troubleshoot this JavaScript that won't work in IE?
          ben.duffin86

          Is there another script setting the window.onload function?  Perhaps they're conflicting.  I would recommend putting your script in a jQuery ready function:

           

          $j(function() {
              var currentuser = window.parent._jive_current_user.displayName; 
          
              if (currentuser == 'ANONYMOUS') {
                  document.getElementById("registered-output").innerHTML = "<div class='register-container'><div class='register-header'><div class='register-header-holder'><p class='header-text'>Register</p></div><div class='register-toptext'><p class='titled'>Why join our community?</p></div></div><div class='register-ul'><ul class='register'><li class='register-li'>Learn through asking questions and getting answers</li><li class='register-li'>Share your expertise on issues, best practices, and experiences</li><li class='register-li'>Network with a global community of engineering professionals</li></ul></div><div class='register-join'><a href='https://mentor.jiveon.com/create-account.jspa'><img src='http://mentor.jiveon.com/resources/statics/16528/join-here-smaller.png'></a></div></div>";
              }
              else {
                  document.getElementById("registered-output").innerHTML = "<div class='register-container-stuff'><div class='register-header'><div class='register-header-holder'><p class='header-text'>Personal Settings</p></div><div class='register-toptext'><p class='header'>Welcome " + currentuser + "</p></div></div><div class='register-ul-two'><table><tr><td><img src='/resources/statics/16528/content.png'></td><td> </td><td><a target=_new href='people/" + window.parent._jive_current_user.username + "/content');'>Your Content</a></td></tr><tr><td><img src='/resources/statics/16528/activity.png'></td><td> </td><td><a target=_new href='people/" + window.parent._jive_current_user.username + "/activity');'>Your Activity</a></td></tr><tr><td><img src='/resources/statics/16528/connections.png'></td><td> </td><td><a target=_new href='people/" + window.parent._jive_current_user.username + "/people');'>Your Connections</a></td></tr><tr><td><img src='/resources/statics/16528/places.png'></td><td> </td><td><a target=_new href='people/" + window.parent._jive_current_user.username + "/places');'>Your Places</a></td></tr><tr><td><img src='/resources/statics/16528/bookmarker.png'></td><td> </td><td><a target=_new href='people/" + window.parent._jive_current_user.username + "/bookmarks');'>Your Bookmarks</a></td></tr></table></div></div>";
              }
          });
          
          
          • Re: Re: Can anyone troubleshoot this JavaScript that won't work in IE?
            ronanfeely

            Thank you, Ben Duffin and Noel White ... using both these suggestions together I can get the JQuery to work on  Jive.

             

            The only issue is I'm still seeing the same behavior I saw when using JavaScript- namely, the widget contents show up intermittently in IE. The contnent always shows up in Chrome and FF but IE is just killing it/me with its will it/won't it behavior.

             

            Here's the code that's in my HTML widget to show the gist of what I'm passing the system using both your suggestions (I cut a lot of the styling and the output for space's sake). Can you see anything I'm overlooking that would cause this IE issue?

             

            R.

             

            <style type="text/css">

            #registered-output {

                position:absolute;

                top:0px;

                height:211px;

                width:200px;

                border: 0px solid #bbc2cd;

            }

            </style>

             

             

            <div id="registered-output"></div>

             

            <script src="/resources/scripts/jquery/jquery.js"></script>

             

            <script>

            var $j = jQuery.noConflict();

             

            $j(document).ready(function(){

             

            var currentuser = window.parent._jive_current_user.displayName; 

            var useremail = window.parent._jive_current_user.username;

             

            if (currentuser == 'ANONYMOUS') {

            $j("#registered-output").html("<div class='register-container'>Register text coded here if the user isn't logged in.</div>");

            }

            else if (currentuser != 'ANONYMOUS') {

            $j("#registered-output").html("<div class='register-container-stuff'>Personalized settings coded here if the user is logged in.</div>")

            }

            ); 

            </script>

            • Re: Can anyone troubleshoot this JavaScript that won't work in IE?
              it2000

              The IE script debugger should output an error ... without it it's hard to fix.

              • Re: Can anyone troubleshoot this JavaScript that won't work in IE?
                ronanfeely

                So far, by a process of trial and error it looks like it's the Jive platform which may have issues with selection statements, not the code. I'm hoping someone can prove me wrong.

                 

                Neither of these two most simple of all selection JavaScripts/JQuery scripts work in IE. Still the same behavior exhibits - either it doesn't display anything (50% of the time), flashes the content briefly but then disappears (30% of the time) or appears as expected (20%).

                 

                <script type="text/javascript">

                window.onload = loadScript;

                function loadScript() {

                var currentuser = "Ronan"; 

                var useremail = "Ronan Feely"; 

                if (currentuser == 'Ronan') {

                document.getElementById("registered-output").innerHTML = "<p>Ronan</p>";

                }

                else {

                document.getElementById("registered-output").innerHTML = "<p>Not Ronan</p>";

                }

                }

                </script>

                 

                <script>

                var $j = jQuery.noConflict();

                $j(document).ready(function(){

                var mycurrentuser = "Ronan";

                var myuseremail = "Ronan Feely";

                if (mycurrentuser == 'Ronan')

                {

                $j("#registered-output").html("<div class='register-container-stuff'><p>Ronan</p></div>")

                }

                else {

                $j("#registered-output").html("<div class='register-container-stuff'><p>Not Ronan</p></div>")

                }

                });   

                </script>

                 

                Gah! This is doing my head in. Going to try putting the script in it's own file and calling it from the widget.

                • Re: Can anyone troubleshoot this JavaScript that won't work in IE?
                  ronanfeely

                  So it wasn't my script after all. It was my CSS. Gah, I wasted a day on that. Apologies for doubting thee, Jive. And thanks for the input folks.