Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What am I doing wrong? 1

Status
Not open for further replies.

bnymk

Programmer
Feb 7, 2003
296
US
Hi all:

I have created a .js file that have some functions that will get executed when the application loads on a user's browser. Inside the functions, I was trying to prevent some of the codes from being executed depending on the page's url and it works if I only supply one page url in the if/else clause but fails to work if I supply multiple urls. Below is the code that I have.

function CNETLogout_OnLoad()
{
if(self.location.href != " try{

//Check if already altered
if (!CNETlogoutOnLoadDone){

//Get all table cells
var tableCellCol = document.getElementsByTagName("Td");

//Look for "ms-banner" class - should only be one
for(var i=0;i<tableCellCol.length;i++){

var cellElm = tableCellCol(i);

//If match found...
if (cellElm.className == "ms-banner"){

//Add Link for "Logout"
cellElm.innerHTML += <a href=javascript:CNETLogoff()>Log Out</a>";
break;
}

}

//Set altered flag
CNETlogoutOnLoadDone = true;

}

}
catch(e){
//Do Nothing - if it doesn't work then no logout appears
}
}
}
}

if I add more than one page to be validated in the if/else clause like this then the whole validation fails and displays the "Logout" link on every single page.

eg.
if(self.location.href != " || self.location.href != " try{
the rest of the code from above goes here....

Could someone please let me know what I'm doing wrong.

Thanks in advance.

"Behind every great fortune there lies a great crime", Honore De Balzac
 
Maybe just a typo?.. but instead of "or" shouldn't it be "and"?

Code:
if(self.location.href != "[URL unfurl="true"]http://xxx.xxx.xxx.xxx/default.aspx"[/URL] && self.location.href != "[URL unfurl="true"]http://xxx.xxx.xxx.xxx/secondpage.aspx"){[/URL]
...
}
 
Okiiyama:

You are correct. I don't know how I missed that. Must have been tired. Anyway, thanks for taking a look at my code and pointing out my silly mistake.

Cheers.

"Behind every great fortune there lies a great crime", Honore De Balzac
 
have a star!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top