User325313 User325313 - 1 year ago 44
Javascript Question

Show/Hide content by checking 2 differen URLS first

I'm running a code that displays content based on the url. If the user is in page X, the page displays the content number 1 and hides number 2, if he's in page Y, it displays the content number 2 and hides number 1. It works, but I would like to add a second URL to be checked.

My code is as follows:


var url = document.location.href;
if(url == "") {

} else {


I tried using something like this, but it didn't work:

if(url == "" && url == "") {

Ish Ish
Answer Source

Use OR instead of AND as the URL can be either of them.

if(url == "" || url == "")