1 //1******** 擷取檔案上傳對話方塊中的全路徑 2 3 <script type="text/javascript"> 4 function upload() { 5 var filename = document.getElementById("importFile").value; 6 alert(filename); 7 } 8 </script> 9 10 11 //html12 <input type="file" id="importFile" />13 <input type="button" onclick="upload()"/>
1 //2******** 擷取檔案上傳對話方塊中的路徑檔案夾名 2 3 <script type="text/javascript"> 4 var filename = document.getElementById("importFile").value; 5 alert(filename); 6 7 var sFileName = new Array(); 8 sFileName = filename.split('\\'); 9 10 len = sFileName.length11 var thisFileName = sFileName[len - 2]12 alert(thisFileName);13 </script>14 15 16 //html17 <input type="file" id="importFile" onclick="upload()“/>18 <input type="button" onclick="upload()"/>
1 //3***********擷取當前檔案全路徑 2 3 <script language="javascript"> 4 5 alert(window.location.href); 6 7 alert(window.location); 8 9 alert(location.href); 10 11 alert(parent.location.href); 12 13 alert(top.location.href); 14 15 alert(document.location.href); 16 17 alert(document.URL);18 19 </script>20 21 //4*************擷取當前頁面所在的目錄方法22 23 <script type="text/javascript">24 25 //方法一26 27 var str = location.href;28 29 var arr = str.split("/");30 31 delete arr[arr.length-1];32 33 var dir = arr.join("/");34 35 alert(dir);36 37 //方法二38 39 alert(location.href.substring(0,location.href.lastIndexOf('/')));40 41 </script>42 43 44 45 //5*******************擷取當前頁面所在的檔案名稱46 47 <script language=javascript> 48 49 var filename=location.href;50 51 filename=filename.substr(filename.lastIndexOf('/')+1); 52 53 alert(filename); 54 55 </script>