Dear all,
I am using the script below for reading an url and automatically add to one the "Protocol" Http or Https. The script below reading only https or http, because I cannot add another ELSE IF. This script is good for any url starting by "www", but many urls don´t starting by "www". So I have 2 problems. Could someone help me to improve this code for adding automatically the protocol and independetly if starts or not by 'www'?
<script>
function formatURL()
{
var url = document.getElementsByName
("URL")[0]
;
var formattedURL = document.getElementsByName
("formatte
dURL")[0];
url = url.value;
if(url.substr(0,3) === "www") // it is for an url starting by www but I need for urls starting or not by www
{
formattedURL.value = "
http://"+url;
return;
}
// I need here other alternative to
https:
}
formattedURL.value = url;
}
</script>
The results are reading by a form that "convert" the url without http or https with www or without www to real url to open it in another screen
Sorry by the inconveniences
Sincerely
Letchev
You don't actually have an else if in the posted code and you can have multiple else if statements