Question

I have an issue with a piece of JavaScript that won't behave correctly in IE. All other platforms are OK.

There is a simple JavaScript that takes a system value and uses that to see if a user is logged in and the places HTML into a div accordingly. It will not load in IE until I do a Ctrl-F5, however.

Any help would be great as I'm really stumped on this.

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

<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='header'>Why join our community?</p></div></div><div class='register-ul'><ul class='register'><li class='register-li'>Here's one good reason</li><li class='register-li'>Networking with others</li><li class='register-li'>Start or join a discussion</li><li class='register-li'>Tech notes</li><li class='register-li'>Networking with others</li></ul></div><div class='register-join'><a href='https://mentor.jiveon.com/create-account.jspa'><img src='http://mentor.jiveon.com/resources/statics/15536/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 " + useremail + "</p></div></div><div class='register-ul-two'><table><tr><td><img src='/resources/statics/15536/content.png'></td><td>&nbsp;</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/15536/activity.png'></td><td>&nbsp;</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/15536/connections.png'></td><td>&nbsp;</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/15536/places.png'></td><td>&nbsp;</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/15536/bookmarker.png'></td><td>&nbsp;</td><td><a target=_new href='people/" + window.parent._jive_current_user.username + "/bookmarks');'>Your Bookmarks</a></td></tr></table></div></div>";
}
}

</script>

I have written this code to fit inside a HTML widget on the Jive platform.

Était-ce utile?

La solution

Your code

window.onload = loadScript();

is wrong. You are calling the function, not assigning it. Drop the ()

window.onload = loadScript;

Autres conseils

    window.onload = loadScript(); // will cause the function to execute immediately
    window.onload = loadScript; // will cause the function to execute on load

Just remove the () so the function can work as a callback.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top