Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
124
rated 0 times [  129] [ 5]  / answers: 1 / hits: 25866  / 12 Years ago, mon, august 27, 2012, 12:00:00

I have developed a web application in asp.net, there is a page in this project which user should choose a file in picture format (jpeg, jpg, bmp,...) and I want to preview image in the page but I don't want to post file to server I want to handle it in client i have done it with java scripts functions via file API but it only works in IE9 but most of the costumers use IE8 the reason is that IE8 doesn't support file API is there any way to make IE8 upgrade or some patches in code behind I mean that check if the browser is IE and not support file API call a function which upgrades IE8 to IE9 automatically.



I don't want to ask user to do it in message I want to do it programmatically!!

even if it is possible to install a special patch that is required for file API
because customers thought it is a bug in my application and their computer knowledge is low
what am I supposed to do with this?

I also use Async File Upload Ajax Control But it post the file to server any way with ajax solution and HTTP handler but java scripts do it all in client browser!!!


following script checks the browser supports API or not



<script>
if (window.File && window.FileReader && window.FileList && window.Blob)
document.write(<b>File API supported.</b>);
else
document.write('<i>File API not supported by this browser.</i>');
</script>


following scripts do the read and Load Image



function readfile(e1)
{
var filename = e1.target.files[0];
var fr = new FileReader();
fr.onload = readerHandler;
fr.readAsText(filename);
}


HTML code:



<input type=file id=getimage>

<fieldset><legend>Your image here</legend>
<div id=imgstore></div>
</fieldset>


JavaScript code:



<script>
function imageHandler(e2)
{
var store = document.getElementById('imgstore');
store.innerHTML='<img src=' + e2.target.result +'>';
}

function loadimage(e1)
{
var filename = e1.target.files[0];
var fr = new FileReader();
fr.onload = imageHandler;
fr.readAsDataURL(filename);
}

window.onload=function()
{
var x = document.getElementById(filebrowsed);
x.addEventListener('change', readfile, false);
var y = document.getElementById(getimage);
y.addEventListener('change', loadimage, false);
}
</script>

More From » asp.net

 Answers
4

You can't install anything special to add support for File API in IE8. What you can do is use a polyfill in order to implement this functionality in browsers that don't natively support it. Take a look at this list of HTML5 Cross Browser Polyfills (you should find something suitable for you in File API / Drag and Drop section).


[#83407] Saturday, August 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kinsley

Total Points: 352
Total Questions: 84
Total Answers: 94

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
;