Asp.net+javascript

How do u get the file name from a particular path using Javascript?

Questions by shra1kalyani   answers by shra1kalyani

Showing Answers 1 - 2 of 2 Answers

dinesh

  • Apr 13th, 2013
 

use indexOf

indexOf(path)

rupinder

  • Apr 16th, 2013
 

Code
  1. function getFileName() {

  2. //this gets the full url

  3. var url = document.location.href;

  4. //this removes the anchor at the end, if there is one

  5. url = url.substring(0, (url.indexOf("#") == -1) ? url.length : url.indexOf("#"));

  6. //this removes the query after the file name, if there is one

  7. url = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?"));

  8. //this removes everything before the last slash in the path

  9. url = url.substring(url.lastIndexOf("/") + 1, url.length);

  10. //return

  11. return url;

  12. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions