1. IE browser
6: directly obtain the value of the inputFile object and fill it in the src of the img tag.
7 ++: the absolute path cannot be used to display images due to browser security restrictions. The AlphaImageLoader filter technique is required ()
Filter: progid: DXImageTransform. Microsoft. AlphaImageLoader (enabled = bEnabled, sizingMethod = sSize, src = sURL)
Paste a filter description blog
The above code is more practical:
Var imageUrl = document. selection. createRange (). text;
Document. selection. empty ();
InputFile. src = "")
Img. src = "";
Img. style. filter = "progid: DXImageTransform. Microsoft. AlphaImageLoader (enabled = true, sizingMethod = scale, src = '" + imageUrl + "')";
2 modern browsers
Chrome
Checks whether the browser supports FileReader objects
FileReaer. result returns the File content
Var reader = new FileReader ();
Reader. readAsDataURL (self. inputFile. files [0]);
Reader. onload = function (evt) {img. src = evt.tar get. result;
FF
InputFile. files. item (0). gettAsDataURL (); // supported by FF. The version is not supported.
These are all code snippets.