当前位置: 代码迷 >> JavaScript >> JAVAscript在IE和Firefox上分别获取下传图片的全路径
  详细解决方案

JAVAscript在IE和Firefox上分别获取下传图片的全路径

热度:24   发布时间:2012-10-27 10:42:26.0
JAVAscript在IE和Firefox下分别获取上传图片的全路径

<html>
??? <head>
??????? <title>get file input full path</title>
??? <script language='javascript'>
??????? function getFullPath(obj)
??????? {
??????????? if(obj)
??????????? {
??????????? ?alert(window.navigator.userAgent);
??????????????? //ie
??????????????? if (window.navigator.userAgent.indexOf("MSIE")>=1)
??????????????? {
??????????????? ?alert("ie");
??????????????????? obj.select();
??????????????????? document.selection.createRange().text
??????????????????? return document.selection.createRange().text;
??????????????? }
??????????????? //firefox
??????????????? else if(window.navigator.userAgent.indexOf("Firefox")>=1)
??????????????? {
??????????????? ?alert("ff");
??????????????????? if(obj.files)
??????????????????? {
??????????????????????? return obj.files.item(0).getAsDataURL();
??????????????????? }
??????????????????? return obj.value;
??????????????? }
??????????????? return obj.value;
??????????? }
??????? }
??? </script>
??? </head>
??? <body>
??????? <input type="file" onchange="document.getElementById('img').src=getFullPath(this);" />
??? <img id="img" />
??? </body>
</html>

  相关解决方案