Reputation: 3628
There is some code a co-worker implemented a while back on a dev environment that we never got to test and implement into production, but now we are wanting to. Testing out the code I have no issues when using Chrome v43, or Firefox v37 on Ubuntu 12.04, however some other staff are reporting issues.
Some users get the tab/browser hanging on the page and then crashing, and some don't have any issues and the script works as intended, like myself. On some machines only one browser is crashing, and the other works.
I have read over the whole code snippet multiple times and I am unable to determine what within it would be prone to crashes/hangups in it.
Here is the Javascript:
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
$(document).ready(function(){
$('a').click(function(){
var address = $(this).attr("href");
if(address == "/twiki-dev/view/TWiki/WelcomeGuest?logout=1"){
eraseCookie("MOD_AUTH_CAS_S");
}
});
});
var allCookies = document.cookie.split(";");
var newHref = "";
for(i=0; i<allCookies.length; i++) {
var cookie = allCookies[i].split("=");
var redirect = 0;
if(cookie[0].trim() === "MOD_AUTH_CAS_S") {
var hrefSplit = document.URL.split("/");
for(i=0; i<hrefSplit.length; i++) {
if(hrefSplit[i]=="view") {
if("TWikiGuest"=="%WIKINAME%") {
redirect = 1;
};
hrefSplit[i]="viewauth";
}
if(i == hrefSplit.length-1) newHref = hrefSplit[i];
else newHref = hrefSplit[i] + "/";
}
if(redirect ==1) {
document.getElementsByTagName('body')[0].style.display = "none";
window.location.href = newHref;
}
}
}
Is there a code problem here that would be causing an issue?
Edit: One browser reported var hrefSplit = document.URL.split("/");
as being the culprit but I don't see what there could cause an issue?
Upvotes: 0
Views: 224
Reputation: 46
Your are using the same local variable "i" in inside the same loop. Try to change inner loop variable to "j" or whatever.
Upvotes: 1