Find substring from a URL - Javascript String

Javascript examples for String:substring

Description

Find substring from a URL

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <script type="text/javascript">
     var str  = "http://www.example.com/#tabname-1-12";
     var val1 = str.substr(20,7);
     var val2 = str.substr(28,1);
     var val3 = str.substr(31,2);
function displayVal()/*w  w  w. ja  va2  s  . c om*/
{
    console.log("val1 = "+val1+"\nval2 = "+val2+"\nval3 = "+val3);
}

      </script>
       URL: http://www.example.com/#tabname-1-12; 
      <input type="button" name="btn" value="Click" onclick="displayVal()">  
   </body>
</html>

Related Tutorials