---
title: "javascript 获取表单file全路径"
author: "qingzuochen"
date: "2010-07-08T18:13:23Z"
tags: []
categories: ["Web前端"]
slug: "javascript-file"
draft: false
lastmod: "2010-07-08T18:13:23Z"
id: 708569
url: "https://zochen.iteye.com/blog/708569"
---

ie8下通过obj.value方式得到的是X:\fakepath\XXX


```html
<html>
<head>
<title>get file input full path</title>
<script language='javascript'>
function getFullPath(obj)
{
if(obj)
{
//ie
if (window.navigator.userAgent.indexOf("MSIE")>=1)
{
obj.select();
return document.selection.createRange().text;
}
//firefox
else if(window.navigator.userAgent.indexOf("Firefox")>=1)
{
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>
```