Jack Jack - 1 year ago 67
Javascript Question

Checking a URL in an if/else statement?

I'm trying to check a submitted URL (excluding any additional paths).

The user submitted URL is:

var inputUrl = document.getElementById("inputVal").value;


If the user submits
'http://stackoverflow.com/questions/ask'
then I'm trying to create an if/else statement that will determine whether the site is 'stackoverflow.com', regardless of
'http/https'
or any
'/.../.../'
after
.com


if (inputUrl == "stackoverflow.com") {
console.log ("stackoverflow");
} else {
console.log("not stackoverflow");
}


Any help would be greatly appreciated.

Answer Source
   if(inputUrl.toLowerCase().indexOf("stackoverflow.com") > -1) {
       ...
   }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download