avatar

tetsai

原创声明

本文由tetsai原创,转载请注明来源

插入下列兼容js即可

<!-- Enable window.atob surpport -->
<script>if(!window.atob){var sc=document.createElement('script');sc.type='text/javascript';sc.async=false;var s=document.getElementsByTagName('script')[0];sc.src='//cdnjs.cloudflare.com/ajax/libs/Base64/1.0.2/base64.min.js';s.parentNode.insertBefore(sc,s);}</script>
<!-- END-->

它会检测当前浏览器是否支持window.atob/btoa,如果不支持则调用js进行弥补,如果原生支持就算了

其中atob是base64解码,btoa是base64编码

base64.min.js

依赖文件下载地址:

https://cdnjs.cloudflare.com/ajax/libs/Base64/1.0.2/base64.min.js

文件不长我就把它贴在这里留作备份

!function(){var e="object"==typeof exports&&null!==exports&&"number"!=typeof exports.nodeType?exports:"undefined"!=typeof self?self:$.global,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function f(e){this.message=e}(f.prototype=new Error).name="InvalidCharacterError",e.btoa||(e.btoa=function(e){for(var t,r,o=String(e),n=0,a=c,i="";o.charAt(0|n)||(a="=",n%1);i+=a.charAt(63&t>>8-n%1*8)){if(255<(r=o.charCodeAt(n+=.75)))throw new f("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");t=t<<8|r}return i}),e.atob||(e.atob=function(e){var t=String(e).replace(/[=]+$/,"");if(t.length%4==1)throw new f("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,o,n=0,a=0,i="";o=t.charAt(a++);~o&&(r=n%4?64*r+o:o,n++%4)?i+=String.fromCharCode(255&r>>(-2*n&6)):0)o=c.indexOf(o);return i})}();

发表评论

电子邮件地址不会被公开。 必填项已用*标注