a.html 页面
< ! DOCTYPE html>
< html lang= "en" >
< head> < meta charset= "UTF-8" > < title> 在浏览器打开< /title> < meta name= "renderer" content= "webkit" > < meta http-equiv= "X-UA-Compatible" content= "IE=edge,chrome=1" > < ! -- 优先使用 IE 最新版本和 Chrome --> < meta name= "viewport" content= "width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" > < style> .fxTis img{ width: 100%; display: inline-block; } .fxTis{ text-align: center; } .fxTis button{ border: 0; padding: 6px 14px; background-color: font-size: 18px; border-radius: 4px; } < /style>
< /head>
< body style= "background-color: #333333;" >
< div class= "fxTis" > < button type= "button" onclick= "onDocDownload('http://cms.heromutual.com/u/cms/huiyou/201909/09144922jmgw.pdf')" > 文件< /button>
< /div>
< /body>
< script src= "js/jquery.min.js" > < /script>
< script> function onDocDownload( filepath) { window.top.location.href= "browser.html?fileurl=" +filepath; }
< /script>
< /html>
分享.html 页面
< ! DOCTYPE html>
< html lang= "en" >
< head> < meta charset= "UTF-8" > < title> 在浏览器打开< /title> < meta name= "renderer" content= "webkit" > < meta http-equiv= "X-UA-Compatible" content= "IE=edge,chrome=1" > < ! -- 优先使用 IE 最新版本和 Chrome --> < meta name= "viewport" content= "width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" > < style> .fxTis img{ width: 100%; display: inline-block; } .fxTis{ text-align: center; } .fxTis button{ border: 0; padding: 6px 14px; background-color: font-size: 18px; border-radius: 4px; } < /style>
< /head>
< body style= "background-color: #333333;" > < div class= "fxTis" > < img src= "images/fx.jpg" > < button type= "button" > 在浏览器中打开< /button> < /div>
< /body>
< script src= "js/jquery.min.js" > < /script>
< script> //从浏览器url地址中获取参数对应的值function GetRequest( ) { var url = location.search; //获取url中"?" 符后的字符串var theRequest = new Object( ) ; if ( url.indexOf( "?" ) != -1) { //存在? 则var str = url.substr( 1) ; strs = str.split( "&" ) ; //字符串分割for( var i= 0; i< strs.length; i++) { theRequest[ strs[ i] .split( "=" ) [ 0] ] = ( strs[ i] .split( "=" ) [ 1] ) ; } } return theRequest; } //判断是否是微信浏览器function is_weixin( ) { var ua = window.navigator.userAgent.toLowerCase( ) ; if ( ua.match( /MicroMessenger/i) == 'micromessenger' ) { console.log( '微信浏览器' ) ; return true ; } else { console.log( "不是微信浏览器" ) ; return false ; } } var is_weixin= is_weixin( ) ; if( is_weixin) { //是微信浏览器 显示返回按钮 (用户可以选择下载或者返回)$( '#back_btn' ) .show( ) ; } else{ //不是微信浏览器//执行下载window.location.href= GetRequest( ) .fileurl; }
< /script>
< /html>
用浏览器打开就能直接下载文件了