Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to download files in html5

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to download files in html5". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to download files in html5".

Demand analysis

Received the demand when I secretly happy, the biggest advantage of this H5 page is not used in Wechat (Wechat crappy, a variety of restrictions, basically from the Wechat browser to achieve direct download apk is impossible), if it is in a normal browser, it is much easier.

Function realization

So I thought of the first one, changing location.href when you click the download button.

Method 1:

/ / I randomly found a download link for apk, for example, _ window.location.href = 'http://imtt.dd.qq.com/16891/26747DD8B125A8479AD0C9D22CA47BC9.apk?fsname=com.snda.wifilocating_4.2.91_3211.apk&csr=1bbd';

I tried it in the browser, and several Android models worked, and then I happily assigned the task, packed up and went home.

And then.

The blank page in the screenshot is because I changed href to the download link of apk. When the web page opens, it will stay in a blank page, and then the progress bar for downloading apk will appear on the status bar of the phone.

Since you don't want to see a blank page, just open a page instead of the current page.

When you think of iframe, you can open a page on the original page with the help of iframe.

Method 2:

Key code:

Var src = 'http://imtt.dd.qq.com/16891/26747DD8B125A8479AD0C9D22CA47BC9.apk?fsname=com.snda.wifilocating_4.2.91_3211.apk&csr=1bbd';var iframe = document.createElement (' iframe'); iframe.style.display = 'none';iframe.src = "_ javascript:' location.href="+ src +"; document.getElementsByTagName ('body') [0] .appendChild (iframe)

Using iframe, you can download without reopening the page, and it won't have any effect on the layout of the original page.

Method three

The third method is learned by accident, since it is possible to use iframe, it must be possible to use form, and the action of form can also make requests.

So the second method is rewritten:

Var src = 'http://imtt.dd.qq.com/16891/26747DD8B125A8479AD0C9D22CA47BC9.apk?fsname=com.snda.wifilocating_4.2.91_3211.apk&csr=1bbd';var form = document.createElement (' form'); form.action = src;document.getElementsByTagName ('body') [0] .appendChild (form); form.submit () Thank you for your reading, the above is the content of "how to download files in html5", after the study of this article, I believe you have a deeper understanding of how to download files in html5, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report