Created
December 24, 2014 18:17
-
-
Save sammydigits/91fa6906bd66ddb718d4 to your computer and use it in GitHub Desktop.
Exact filename from 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
| function getFileName() { | |
| //this gets the full url | |
| var url = document.location.href; | |
| //this removes the anchor at the end, if there is one | |
| url = url.substring(0, (url.indexOf("#") == -1) ? url.length : url.indexOf("#")); | |
| //this removes the query after the file name, if there is one | |
| url = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?")); | |
| //this removes everything before the last slash in the path | |
| url = url.substring(url.lastIndexOf("/") + 1, url.length); | |
| //return | |
| return url; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment