---
title: "获取本地图片的预览地址"
author: "tarsean"
date: "2015-11-22T11:28:47Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2015-11-22T11:28:47Z"
id: 2258353
url: "https://tarsean.iteye.com/blog/2258353"
---

var url = '';

if (navigator.userAgent.indexOf("MSIE")&gt;=1) { // IE   
     url = document.getElementById(sourceId).value;   
} else if(navigator.userAgent.indexOf("Firefox")&gt;0) { // Firefox   
    url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));   
} else if(navigator.userAgent.indexOf("Chrome")&gt;0) { // Chrome   
     url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));   
}