简体   繁体   English

jQuery隐藏iframe文件上传

[英]jQuery hidden iframe File upload

We're attempting to upload a file using a hidden iframe and the script runs in all browsers except IE(9). 我们正在尝试使用隐藏的iframe上传文件,并且脚本在除IE(9)之外的所有浏览器中运行。

  • The user clicks on a link 用户点击链接
  • Link triggers file input to open 链接触发文件输入打开
  • File input change triggers form submit 文件输入更改触发器表单提交
  • Form submits to iframe 表单提交iframe

IE9 developer tool returns the following error message: IE9开发人员工具返回以下错误消息:

SCRIPT5: Access is denied.
jquery-latest.js, line 2977 character 6

Looking around, it seems to be an error that occurs alongside the jQuery change() event. 环顾四周,它似乎是与jQuery change()事件一起发生的错误。 Fairly sure it must be a simple solution... Many thanks if you are able to help! 相当肯定它必须是一个简单的解决方案...非常感谢你能够提供帮助!

HTML HTML

<form class="hidden" action="index.php?upload" method="POST" id="myForm" enctype="multipart/form-data" target="hidden_iframe">
    <input type="file" name="userfile" id="userFile">
    <input type="submit">
</form>

<iframe id="hidden_iframe" class="hidden" name="hidden_iframe" src="inc/temp.html"></iframe>

Javascript 使用Javascript

$('#fake').on("click",function(e){
    e.preventDefault();
    $('#userFile').click();
    return false;
});
$('#real').on("change",function(e){
    e.preventDefault();
    $("#myForm").submit();
});

This is IE security setting. 这是IE安全设置。 Just go to Settings->Internet Options->Security->Custom Level and change security settings under "Miscellaneous" set "Access data sources across domains" to Enable. 只需转到“设置” - >“Internet选项” - >“安全性” - >“自定义级别”,然后将“其他”设置“跨域访问数据源”下的安全设置更改为“启用”。

EDIT: 编辑:

I just saw what's the problem. 我刚刚看到了什么问题。 You're triggering the file upload and you're not allowed to do that. 您正在触发文件上传,但您不允许这样做。 You need to let the user manually click the file-selector button. 您需要让用户手动单击文件选择器按钮。

Maybe you should consider an alternate solution altogether? 也许你应该考虑一个替代解决方案?

Uploading through a hidden iframe isn't the best way to do this nowadays. 通过隐藏的iframe上传不是现在最好的方法。

Have a look at this awesome lib instead: http://www.plupload.com/ 请看看这个很棒的lib: http//www.plupload.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM