百度搜索了很多哩掺,但是始終沒有完成需求,只是在ios瀏覽器上下載個pdf涩笤,麻煩的要死嚼吞,希望華為或者小米的生態(tài)能早點做起來盒件。
<body>
????<button?id="download">down</button>
</body>
<script>????var?url?=????????"https://teXXXXXXXXXXXXXXXXXXXX"? ? ? var?down?=?document.getElementById('download')? ? ? down.onclick?=?function?()?{????????var?ua?=?navigator.userAgent.toLowerCase();????????//判斷是不是在iPhone的Safair瀏覽器打開的本頁面? ? ? ? ?if?(ua.indexOf('applewebkit')?>?-1?&&?ua.indexOf('mobile')?>?-1?&&?ua.indexOf('safari')?>?-1?&&????????????ua.indexOf('linux')?===?-1?&&?ua.indexOf('android')?===?-1?&&?ua.indexOf('chrome')?===?-1?&&????????????ua.indexOf('ios')?===?-1?&&?ua.indexOf('browser')?===?-1)?{????????????//?document.write("【是?Safari】");????????????down1(url)????????}?else?{????????????//?document.write("【不是?Safari】");????????????down2(url)????????}????}????function?down1(url)?{????????var?src?=?url????????var?iframe?=?document.createElement('iframe');????????iframe.style.display?=?'none';????????iframe.src?=?"javascript:?'<script>location.href=\""?+?src?+?"\"<\/script>'";? ? ? ? ? ? ?document.getElementsByTagName('body')[0].appendChild(iframe);????}????function?down2(url)?{????????window.open(url)????}</script>
原理就是利用iframe來進行操作