admin管理员组文章数量:1026373
This is my HTML:
<input type="file" id="browse" name="browse" size="" placeholder="Photo" checked="checked" class="upload"/>
<input type="button" onclick="javascript:onbrowse()" class="unknown" value=""/>
And my JavaScript:
$(function() {
$(".upload").change(function () {
var fileObj = $(this).get(0);
var fileName;
if (fileObj.files) {
fileName = fileObj.files.item(0).getAsDataURL()
} else {
fileName = fileObj.value;
}
$(".unknown").css("background-size", "100px 100px");
$(".unknown").css("background-image", "url(" + fileName + ")");
});
});
function onbrowse() {
document.getElementById('browse').click();
}
I have two problems:
onclick doesn't work in Chrome and
getAsDataURL() doesn't work in Chrome and IE
Can you help me?
This is my HTML:
<input type="file" id="browse" name="browse" size="" placeholder="Photo" checked="checked" class="upload"/>
<input type="button" onclick="javascript:onbrowse()" class="unknown" value=""/>
And my JavaScript:
$(function() {
$(".upload").change(function () {
var fileObj = $(this).get(0);
var fileName;
if (fileObj.files) {
fileName = fileObj.files.item(0).getAsDataURL()
} else {
fileName = fileObj.value;
}
$(".unknown").css("background-size", "100px 100px");
$(".unknown").css("background-image", "url(" + fileName + ")");
});
});
function onbrowse() {
document.getElementById('browse').click();
}
I have two problems:
onclick doesn't work in Chrome and
getAsDataURL() doesn't work in Chrome and IE
Can you help me?
Share Improve this question edited Nov 8, 2011 at 13:38 Some Guy 16.2k10 gold badges60 silver badges68 bronze badges asked Nov 8, 2011 at 12:57 Aram MkrtchyanAram Mkrtchyan 2,7004 gold badges35 silver badges48 bronze badges2 Answers
Reset to default 3IE does not yet support the File API. Anyhow, you need to use a FileReader
to read a file. Also, the file is not its file name (your variable naming is a little ambiguous).
The click delegation to the file input works just fine.
http://jsfiddle/fKQDL/
file = fileObj.files[0];
var fr = new FileReader;
fr.onloadend = changeimg;
fr.readAsDataURL(file);
Bind the button's behavior with jQuery
jQuery('input[type="button"].unknown').click ( onbrowse );
This is my HTML:
<input type="file" id="browse" name="browse" size="" placeholder="Photo" checked="checked" class="upload"/>
<input type="button" onclick="javascript:onbrowse()" class="unknown" value=""/>
And my JavaScript:
$(function() {
$(".upload").change(function () {
var fileObj = $(this).get(0);
var fileName;
if (fileObj.files) {
fileName = fileObj.files.item(0).getAsDataURL()
} else {
fileName = fileObj.value;
}
$(".unknown").css("background-size", "100px 100px");
$(".unknown").css("background-image", "url(" + fileName + ")");
});
});
function onbrowse() {
document.getElementById('browse').click();
}
I have two problems:
onclick doesn't work in Chrome and
getAsDataURL() doesn't work in Chrome and IE
Can you help me?
This is my HTML:
<input type="file" id="browse" name="browse" size="" placeholder="Photo" checked="checked" class="upload"/>
<input type="button" onclick="javascript:onbrowse()" class="unknown" value=""/>
And my JavaScript:
$(function() {
$(".upload").change(function () {
var fileObj = $(this).get(0);
var fileName;
if (fileObj.files) {
fileName = fileObj.files.item(0).getAsDataURL()
} else {
fileName = fileObj.value;
}
$(".unknown").css("background-size", "100px 100px");
$(".unknown").css("background-image", "url(" + fileName + ")");
});
});
function onbrowse() {
document.getElementById('browse').click();
}
I have two problems:
onclick doesn't work in Chrome and
getAsDataURL() doesn't work in Chrome and IE
Can you help me?
Share Improve this question edited Nov 8, 2011 at 13:38 Some Guy 16.2k10 gold badges60 silver badges68 bronze badges asked Nov 8, 2011 at 12:57 Aram MkrtchyanAram Mkrtchyan 2,7004 gold badges35 silver badges48 bronze badges2 Answers
Reset to default 3IE does not yet support the File API. Anyhow, you need to use a FileReader
to read a file. Also, the file is not its file name (your variable naming is a little ambiguous).
The click delegation to the file input works just fine.
http://jsfiddle/fKQDL/
file = fileObj.files[0];
var fr = new FileReader;
fr.onloadend = changeimg;
fr.readAsDataURL(file);
Bind the button's behavior with jQuery
jQuery('input[type="button"].unknown').click ( onbrowse );
本文标签: javascriptgetAsDataURL() doesn39t work in chrome and ieStack Overflow
版权声明:本文标题:javascript - getAsDataURL() doesn't work in chrome and ie - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745644592a2160948.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论