> For the complete documentation index, see [llms.txt](https://close.gitbook.io/yun-wei-bi-ji/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://close.gitbook.io/yun-wei-bi-ji/centos/vue/h5-ye-mian-shi-xian-xia-zai-wen-jian.md).

# H5页面实现下载文件

### H5页面实现下载文件(apk)

```html
<div class='Five'></div>
```

### 方法一：

```html
## 效果不好
window.location.href = 'http://xxx.apk';
```

#### 方法二：

关键代码：

```html
## 推荐
$(function(){ 
    $('.Five').click(function(){
        var src = 'http://xxx.apk';
        var iframe = document.createElement('iframe');
        iframe.style.display = 'none';
        iframe.src = "javascript: '<script>location.href=\"" + src + "\"<\/script>'";
        document.getElementsByTagName('body')[0].appendChild(iframe);
    })
})
```

#### 方法三

```html
## 强烈推荐
$(function(){ 
    $('.Five').click(function(){
        var src = 'http://xxx.apk';
        var form = document.createElement('form');
        form.action = src;
        document.getElementsByTagName('body')[0].appendChild(form);
        form.submit();
    })
})
```
