jQuery input file click method and access denied on IE

牧云@^-^@ 提交于 2019-12-06 06:19:38

I found a way around it. Wrap the button in label tags like this:

<label for="fileinput"><div class="button">Upload file</div></label>


<form>
  <input id="fileinput" name="file" type="file">
</form>

Clicking the label will trigger the file input without invalidating the form in internet explorer (tested in IE9 & IE10)

EDIT: serve this code to IE and keep the javascript solution for other browsers. Firefox will not trigger the file input field when the label is clicked.

arun.m

I once saw this piece of code, I don't remember where but it is a workaround

  if ($.browser.msie) {
        // IE suspends timeouts until after the file dialog closes
        $flUpload.click(function (event) {
            setTimeout(function () {
                changeFunc();
            }, 0);
        });
    }
    else {
        // All other browsers behave
        $flUpload.change(changeFunc);
    }

Security sandbox "feature" of IE. There is no way to get around it. Sorry. I use the JQuery file input, but still have to detect IE and use the IE basic input, I have spend a lot of time looking for answers and haven't found any. You could use flash, which is what uploadify does to get around the security of IE. I recommend it, it's a pretty damn good plug-in.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!