javascript - How to get part of URL current? -


my url looks like: http://google.com/stackoverflow/post/1

now, want part of url: http://google.com/stackoverflow/ , add code:

post . how ? !

updated:

using javascript:

var url = "http://google.com/stackoverflow/post/1";    // or var url = window.location;  var matches = url.match(/^http\:\/\/([\w\.]+)\/(\w+)\/.+/);  if( matches ){     var newurl = "http://" + matches[1] + "/" + matches[2] + "/";     alert( newurl ); }  document.getelementbyid('post_link').href = newurl; 

html:

<a id="post_link">post</a> 

see jsfiddle


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -