I was wondering if it was possible for jQuery to find a file extension based on a returned string?
A filename (string) will be passed to a function (openFile) and I wanted that function to do different things based on what file has been passed through, it could be image files or pdf files.
function openFile(file) {
//if .jpg/.gif/.png do something
//if .zip/.rar do something else
//if .pdf do something else
};
I’ve been looking for something that will find the file’s extension but I can’t seem to find anything.
How about something like this.
Test the live example: http://jsfiddle.net/6hBZU/1/
It assumes that the string will always end with the extension:
EDIT: I mistakenly deleted part of the string in
openFile("somestring.png");. Corrected. Had it in the Live Example, though.