badfl
badfl
  • 发布:2017-03-15 19:36
  • 更新:2021-03-29 14:34
  • 阅读:3347

webview实现下载文件

分类:HTML5+

使用web view嵌入了一个页面,如果页面里面有下载链接,怎么能监听或者调用浏览器来实现下载,现在点击下载没有反应

            mui.plusReady(function() {  
var ws, embed;  

                ws = plus.webview.currentWebview();  
                embed = plus.webview.create("http://www.baidu.com", "ydsj_page", {  
                    top: "46px",  
                    bottom: "0px"  
                });  
                    embed.show();  
})
2017-03-15 19:36 负责人:无 分享
已邀请:
8***@qq.com

8***@qq.com

请问你解决了吗,有办法监听到吗

[已删除]

[已删除]

是下载网页里的apk文件是吗?可以找我帮你解决

  • 8***@qq.com

    怎么解决的啊,帮帮我啊

    2019-07-04 18:57

  • 8***@qq.com

    是第三方页面哦,他页面里点击下载的时候用浏览器打开

    2019-07-04 18:58

  • [已删除]

    回复 8***@qq.com: 知道,自己找我就是

    2019-07-06 09:35

大熊被骗

大熊被骗

有解决吗

大熊被骗

大熊被骗

不知道是否需要的是这样的  

<template>  
    <view>  
        <web-view :src="url" @message="getMessage"></web-view>  
    </view>  
</template>  

<script>  
    var wv;//计划创建的webview  
    export default {  
       onReady() {  
          console.log('当前环境:' + uni.getSystemInfoSync().platform);//如果是安卓才执行  
          if(uni.getSystemInfoSync().platform == 'android')  
          {  
              var currentWebview = this.$mp.page.$getAppWebview() //获取当前页面的webview对象  
              setTimeout(function() {  
                wv = currentWebview.children()[0]  
                var url222 =  wv.getURL();  
                //console.log('当前网址222: '+url222);  
                // 拦截所有页面跳转,可使用参数拦截.apk的跳转  
                wv.overrideUrlLoading({mode:'reject',match:'.*\.apk.*'}, function(e){  
                    uni.showLoading({  
                        title: '下载中...',  
                        mask: false  
                    });  
                    //console.log('拦截的URL666: '+e.url);  
                    var dtask = plus.downloader.createDownload(e.url, {}, function ( d, status ) {   
                        uni.hideLoading();  
                        uni.showToast({  
                            title: '下载成功...',  
                            mask: false,  
                            duration: 1500    
                        });  
                                      // 下载完成    
                                      if ( status == 200 ) {  
                                          plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename),{},{},function(error){    
                                              uni.showToast({    
                                                  title: '安装失败',    
                                                  mask: false,    
                                                  duration: 1500    
                                              });    
                                          })    
                                      } else {    
                                           uni.showToast({    
                                              title: '下载失败,请检查您的网络',    
                                              mask: false,    
                                              duration: 1500    
                                           });    
                                      }      
                                  });  
                                dtask.start();  
                    });  
              }, 1000); //如果是页面初始化调用时,需要延时一下  
          }  

        },  
        data(){  
            return {  
                url:'',  
                id:'',  
                banner: {}  
            }  
        },  
        onLoad(option) {  
            // 目前在某些平台参数会被主动 decode,暂时这样处理。  
            try {  
                this.banner = JSON.parse(decodeURIComponent(option.query));  
            } catch (error) {  
                this.banner = JSON.parse(option.query);  
            }  
            this.url = this.banner;  
        },  
        methods:{  
            getMessage(event) {  
                console.log('提示内容: '+JSON.stringify(event.detail.data));  
                uni.showModal({  
                    content: JSON.stringify(event.detail.data),  
                    showCancel: false  
                });  
            }  
        }  
    }  

</script>  

<style>  

</style>  
3***@qq.com

3***@qq.com

如果下载的是pdf之类的文件怎么解决呢

9***@qq.com

9***@qq.com

你好,请问怎么解决

该问题目前已经被锁定, 无法添加新回复