arrays - Javascript Split URL -
i want split specific parts of url, here have far.
<script type='text/javascript'> var query = window.location.pathname.split( '/' ); query = window.location.pathname.split( '.html' ); var redirectpath = "http://www.mydomain.com/search/?q=" window.location.href = redirectpath + query; </script>
the url structure this:
http://www.mydomain.com/page/2013/05/some-page-title.html
the variable query
outputs this; page,2013,05,some-page-title
i want some-page-title
part , remove hyphens.
so final output http://www.mydomain.com/search/?q=some page title
how possible? please help!! thanks
split returns array, use array!
var parts = window.location.pathname.split( '/' ); var query = parts[parts.length-1].split( '.html' ); query[0]= query[0].replace(/-/g," "); var redirectpath = "http://www.mydomain.com/search/?q=" window.location.href = redirectpath + query[0];
this assuming want part of url after last /
Comments
Post a Comment