I wrote a small script to recreate the Chrome address bar, wherein my code checks an input for any domain extension(.com, .edu etc.) and sets a boolean flag to true if an extension is found. It then checks the flag and based on the result opens the website or sends it to google as a query. Additionally, if it is a website, it checks if the string contains http:// and www. and if not, adds it to the string before using Window.Open() to open the target.
What's wrong here?
function openSite(){
var domain_extensions = [".aero", ".asia", "...All Other Extensions...", ".zr", ".zw"];
var isSite = false;
var userIn = document.getElementById('in_field').value; //Retrieves Textbox code
for (var i=0; i < domain_extensions.length; i++)
if (userIn.search(domain_extensions[i]) !==-1)
isSite = true;
//Checks against the array of extensions
if (isSite === true){
if (userIn.search("http://") === -1 || userIn.search("https://") === -1)
{if(userIn.search("www.") === -1)
userIn = "http://www." + userIn;
else
userIn = "http://" + userIn;
}
window.open(userIn, '_blank');
//if extension is found, open website
//if qualifier http:// or https:// and/or www. not found, append and open website
}
else{
var str = encodeURI("http://www.google.com/search?q=" + userIn);
window.open(str, '_blank');
} //Searches query for common extensions; if not found search google
}
http:backslashbackslash and nothttp://? Also, you may want to usebreak;in your for loop, although I don't think that would fix anything