Created
August 16, 2012 03:48
-
-
Save ysakmrkm/3366433 to your computer and use it in GitHub Desktop.
Get site URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var href = location.href.split('/'); | |
| var path = ''; | |
| var localRegex = /^\d+\.\d+\.\d+\.\d+/; //Local IP Address | |
| var workRegex = /^.*\/pc\/[^\/]+\/.*$/; //Change regex if you want. | |
| for(i = 0 ; i < href.length ; i++){ | |
| if(href[i] == '' || i == href.length - 1 && href[i].indexOf('.') !== -1){ | |
| href.splice(i,1); | |
| } | |
| } | |
| if(localRegex.test(location.hostname) === true || location.hostname.indexOf('localhost') !== -1){ //Local | |
| var length = 2; //Change num if you want. | |
| } else if(workRegex.test(location.href) === true){ //Work | |
| var length = 3; //Change num if you want. | |
| } else { //Production | |
| var length = 1; //Change num if you want. | |
| } | |
| for(j = 0 ; j <= length ; j++){ | |
| path += href[j]; | |
| if(j == 0){ | |
| path += '//'; | |
| } else { | |
| path += '/'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment