我正在制作一个带有文件上传表单的简单 Chrome 扩展程序。当开发人员工具窗口为插件(“检查元素”)打开时,它工作正常,但是当我尝试在没有开发人员工具的情况下运行它时,当我单击文件选择按钮时插件会崩溃。怎么了?我在 OSX 10.7.5 上使用 Chrome 版本 22
代码如下:
这是 HTML 部分:
<!doctype html>
<html>
<head>
<script src="upload.js"></script>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="http://localhost" id="form">
<input type="file" id="file" name="file" >
<input type="button" id="sub" value="Upload">
</form>
</body>
</html>
这是upload.js
function upload(form) {
var formData = new FormData(form);
var req = new XMLHttpRequest();
req.open("POST", form.getAttribute("action"));
req.onload = function(event) {
console.log(event.target.responseText);
};
req.send(formData);
}
document.addEventListener( "DOMContentLoaded", function(){
document.getElementById("sub").addEventListener("click", function() {
upload(document.getElementById("form"));
}, false);
}, false );
这是 manifest.json:
{
"name": "Issue-img",
"version": "1.0",
"manifest_version": 2,
"description": "Simple upload.",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "upload.html"
},
"permissions": [
"http://localhost/"
]
}
提前致谢!