I need to split a URL and store the last half in a variable for example [url]www.site/folder/index.htm[/url] to read /folder/index.htm. The length of the last half or the first is not always the same.
Any help here would be greatly appreciated.
<script type="text/javascript"><!-- var fullURL = window.self.location.href; var splitURL = fullURL.replace(/^(http://)?(www.)?/, "").split("/"); var tmpURL = ""; for(var i = 1; i < splitURL.length; i++){ tmpURL += splitURL[i]+"/"; }; tmpURL = tmpURL.replace(//$/, ""); alert("your folder location is:"+tmpURL); //--> </script>
[CODE]var sPathName = document.location.pathname;[/CODE]
<script type="text/javascript"> <!-- function URL (s) { /^((w+:)/*)?((w+.)?w+.w+)(:(d+))?(/[^?#]+)?(?[^#]+)?(#.+)?/.exec (s); <i> </i>this.protocol = RegExp.$2 || 'http:'; <i> </i>this.host = RegExp.$5 ? RegExp.$3 + ':' + RegExp.$6 : RegExp.$5; <i> </i>this.hostname = RegExp.$3; <i> </i>this.port = RegExp.$6; <i> </i>this.pathname = RegExp.$7; <i> </i>this.search = RegExp.$8; <i> </i>this.hash = RegExp.$9; <i> </i>this.href= RegExp.$2 ? s : this.protocol + '//' + s; <i> </i>if (!this.pathname && !//$/.test (this.href)) this.href = this.href + '/'; } url = new URL ('www.site/folder/index.htm'); alert (url.pathname); // --> </script>
Help @Bryan_Tuffin spread the word by sharing this article on Twitter...