兼容IE,FF的上传图片预览

<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>

posted on 2009-12-18 14:25  骑驴睡觉  阅读(266)  评论(0编辑  收藏  举报

导航