Display the last part of URL javascript? -
i need display last part of url using javascript!
i using code display entire url:
<script language="javascript"> document.writeln(document.location); var url = $(this).attr("href"); var part = url.substring(url.lastindexof('/') + 1); </script>
if url this:
domain.com/something/file
i need display "file".
<script type="text/javascript"> var segment_str = window.location.pathname; // return segment1/segment2/segment3/segment4 var segment_array = segment_str.split( '/' ); var last_segment = segment_array.pop(); document.write(last_segment); // alerts segment4 </script>
jsfiddle: http://jsfiddle.net/hnmv3/1/
Comments
Post a Comment