jQuery val() function and file input field in IE
I have a file inputfile
<input tye='file' id='funPic' name='funPic' />
I need to get the name of the s开发者_如何学JAVAelected file,
$('#funPic').val()
in Firefox and Chrome gives abc.jpg
where as IE7 & IE8 gives c:\xyz\abc.jpg
Why is this? I need only the abc.jpg
part.
Use
$('#funPic').val().split("\\").pop();
Mozilla and other browsers don't give the full path for security reasons. IE will only give the filename when the page runs outside the local security zone.
http://msdn.microsoft.com/en-us/library/ms535126(v=VS.85).aspx
精彩评论