Support IE8 to upload pictures without refreshing the page

For IE8 and IE9, formData is not supported, so uploading files must be done by post page. So how do you upload a picture without refreshing the current page?

In addition to using webuploader, if you don't need to display the progress bar (small files, image uploads are all such requirements), then you can use my method.

Introduce a hidden iframe on the current page, the src of the iframe points to a page where the file is uploaded, click a button or image on the current page, trigger the click of the input of the uploaded file in the iframe, then after selecting a file, let the The page is posted, and then the php page to which the post is sent, after storing the file properly, takes the get parameter back to the original page in the iframe (the one that uploaded the file), at this time, the page uses window.postMessage to send the message (with the uploaded image). HTTP path) is passed back to the current page, the current page receives the message, just set the image path and the value of the input.

The code is in the attachment, and it must be downloaded and run in the root directory of a virtual host.

It can be adjusted according to your own project needs, and the amount of code is very small. This example code does not consider more upload security or special characters in the returned get parameter. In specific projects, these issues should be considered.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326782217&siteId=291194637