如何通過JS獲取用戶本地圖片路徑


直接上代碼 記錄一下

 

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
5 <title>get file input full path</title>
6 <script language='javascript'>
7 function getFullPath(obj)
8 {
9 if(obj)
10 {
11 //ie
12 if (window.navigator.userAgent.indexOf("MSIE")>=1)
13 {
14 obj.select();
15 return document.selection.createRange().text;
16 }
17 //firefox
18 else if(window.navigator.userAgent.indexOf("Firefox")>=1)
19 {
20 if(obj.files)
21 {
22 return obj.files.item(0).getAsDataURL();
23 }
24 return obj.value;
25 }
26 return obj.value;
27 }
28 }
29 </script>
30 </head>
31 <body>
32 <input type="file" onchange="document.getElementById('img').src=getFullPath(this);" />
33 <img id="img" />
34 </body>
35 </html>

 

firefox7+請使用return window.URL.createObjectURL(obj.files.item(0));來獲取地址


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM