Split URL by forward slash / from the 2nd one to the end - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window open

Description

Split URL by forward slash / from the 2nd one to the end

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(){/*  ww  w.  java  2s  .com*/
var url = "www.my.com/store/all-books/nove/book-name/",
    urlParts = url.split('/'),
    newUrl;
urlParts.shift();
urlParts.shift();
urlParts.unshift( '' );
newUrl = urlParts.join('/');
console.log( url );
console.log( newUrl );
    }

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

Related Tutorials