Real-time display of images uploaded in jsp

Source: Internet
Author: User

[Html] <script> function setImagePreview () {var docObj = document. getElementById ("doc"); var imgObjPreview = document. getElementById ("preview"); if (docObj. files & docObj. files [0]) {// under Firefox, set the img attribute imgObjPreview directly. style. display = 'block'; imgObjPreview. style. width = '300px '; imgObjPreview. style. height = '120px '; // imgObjPreview. src = docObj. files [0]. getAsDataURL (); // Firefox 7 or later versions cannot be obtained using the getAsDataURL () method. ImgObjPreview. src = window. URL. createObjectURL (docObj. files [0]);} use the filter docObj under else {// IE. select (); var imgSrc = document. selection. createRange (). text; var localImagId = document. getElementById ("localImag"); // The initial size must be set to localImagId. style. width = "250px"; localImagId. style. height = "200px"; // capture Abnormal images to prevent users from modifying the suffix to counterfeit images. try {localImagId. style. filter = "progid: DXImageTransform. microsoft. alphaImageLoader (si ZingMethod = scale) "; localImagId. filters. item ("DXImageTransform. microsoft. alphaImageLoader "). src = imgSrc;} catch (e) {alert ("the format of the image you uploaded is incorrect. Please reselect it! "); Return false;} imgObjPreview. style. display = 'none'; document. selection. empty () ;}return true ;}</script> <body> <input type = file name = "doc" id = "doc" onchange = "javascript: setImagePreview (); "> <p> <div id =" localImag "> </div> </p>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.