Check URL protocol - Javascript String Operation

Javascript examples for String Operation:String URL

Description

Check URL protocol

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from w  ww .  j a va2  s.c o  m
url="ftp://example.com";
protocols = ['http', 'https', 'ftp', 'sftp', 'ssh', 'smtp'];
protocols.forEach(function(item) {
   if(url.indexOf(item) != -1) {
      newUrl = "http://"+url.substr(url.indexOf("//")+2);
   }
});
console.log(newUrl);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials