Foreword:
In projects, functions such as uploading files and photos are often used, and the size of the uploaded files needs to be limited. Many plug-ins use background request verification, and there are relatively few front-end JS verifications. This article introduces a front-end JS method to conveniently determine the size of uploaded files.
The code is very simple. The key is how to use JS to get the file and then get the file size, and then judge the interception. Due to various historical reasons and IE's ActiveX control factors, the method of obtaining files may be different from other browsers, so you only need to make a little judgment.
JS code:
HTML code
A simple, light and fast method to use JS code to determine the file size is OK. As for the ActiveXObject object, if you are interested, you can delve into it. It can return different objects according to different input parameters. Usually, the function of this object and effects are also very useful and powerful.
That’s it for this article. Isn’t it a very simple and practical code? I hope you all like it.