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
Post a Comment