I want to show a preview image before uploading it. I found a partial solution that works for ie6 and firefox, and havent tested it yet in ie7 or ie8. But I want a solution that works in safari, i.e. 7 etc. Here is the solution obtained by combining the ie6 solution and firefox:
function preview(what) { if(jQuery.browser.msie) { document.getElementById("preview-photo").src=what.value; return; } else if(jQuery.browser.safari) { document.getElementById("preview-photo").src=what.value; return; } document.getElementById("preview-photo").src=what.files[0].getAsDataURL(); // alert(jQuery("#preview-photo").height()); // alert(jQuery("#preview-photo").width()); var h = jQuery("#preview-photo").height(); var w = jQuery("#preview-photo").width();//assuming width is 68, and height is floating if ((h > 68) || (w > 68)){ if (h > w){ jQuery("#preview-photo").css("height", "68px"); jQuery("#preview-photo").css("width", "auto"); }else { jQuery("#preview-photo").css("width", "68px"); jQuery("#preview-photo").css("height", "auto"); } } }
The getAsDataURL () part works in firefox, and the "src = what.value" part works in ie6, but what will work in safari and does "src = what.value" work in ie7 and ie8? If not, is there some kind of solution? I will be glad if I can preview the images in 5 or 6 browsers. If this is not the case, is this the only way to have two forms with the image upload part of another form?
html upload image preview
umar
source share