The function of previewing local images using JavaScript when uploading images in IE is invalid.

Source: Internet
Author: User

Recently, when I was working on a small project, I used JavaScript to preview local images, but I did not display any debugging in IE.

Use IE's developer tool (F12) to debug and monitor Javascript. Path = C:/fakepath/chrysanthemum.jpg

After the document. getelementbyid ("myimg"). src = path is executed, the obtained path is file: // C:/fakepath/chrysanthemum.jpg.

So I started to find a solution on the Internet. Now I will share the solution I found with you!

The reason is that the security option is added to IE8. By default, the actual path of the uploaded file is not displayed. Go to the Internet option and modify the settings to display the actual file path.

The operation is as follows: Tools-> Internet Options-> Security-> Custom Level-> Find "include local directory path when uploading local files to the server" in "others ", select "enable.

Of course, some people will say that you cannot ask your customers to make these settings, so you have to find other solutions.

 1 <SCRIPT type = "text/JavaScript">
2 Function Getpath (OBJ ){
3 If (OBJ ){
4 If (Window. Navigator. useragent. indexof ("MSIE")> = 1 ){
5 OBJ. Select (); Return Document. selection. createRange (). text;
6 }
7 Else If (Window. Navigator. useragent. indexof ("Firefox")> = 1 ){
8 If (Obj. Files ){
9 Return OBJ. Files. Item (0). getasdataurl ();
10 }
11 Return OBJ. value;
12 }
13 Return OBJ. value;
14 }
15 }
16
17 // The complete client path is as follows:
18 VaR Filepath = getpath (document. getelementbyid ("iptfileupload "));
19 </SCRIPT>

The above method does not need to be modified by the customer. You can try it. The above is also the information I found online. I will share it with you for ease of use ~~
 

 

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.