javascript - object doesn't support this property or method btoa - Stack Overflow

admin2025-04-19  0

I know there is already a question on here with solutions for this but I have little understanding of javascript and I can't seem to figure out what they are saying to add in or where. The link to it is here: IExplorer: SCRIPT438: Object doesn't support property or method 'btoa'

Can someone explain to me what they are doing to make it work? Thanks.

I know there is already a question on here with solutions for this but I have little understanding of javascript and I can't seem to figure out what they are saying to add in or where. The link to it is here: IExplorer: SCRIPT438: Object doesn't support property or method 'btoa'

Can someone explain to me what they are doing to make it work? Thanks.

Share Improve this question edited May 23, 2017 at 12:05 CommunityBot 11 silver badge asked Jan 30, 2014 at 17:10 JoshuaJoshua 231 silver badge6 bronze badges 3
  • Not all browsers support .btoa(), so you have to polyfill it for non-supporting browser by adding this script – adeneo Commented Jan 30, 2014 at 17:13
  • Somewhere, your script (or a library that your script uses) tries to call window.btoa. That function doesn't exist in older versions of IE. Instead, you must include a separate JS file (in a <script> tag) that adds the btoa function to the window object. Such a script is called a "shim" or "polyfill" that manually fills in some methods that aren't natively supported in certain browsers. The linked script there (github./davidchambers/Base64.js) is such a shim for btoa. – apsillers Commented Jan 30, 2014 at 17:15
  • @adeneo do I just add this into my file and it should work or do I need to call to this? – Joshua Commented Jan 30, 2014 at 17:23
Add a ment  | 

2 Answers 2

Reset to default 4

Older browsers may not support Window.bota, which is basically an oddly-named method to convert strings to base64 representations, as you probably know.

Making new functionality available in older browsers is called "polyfilling". Put the script base64.js (download) or base64.min.js (download) on your website (I'm going to assume you're using the latter, and putting it in the /js/vendor directory), and reference it thusly (before you need to use Window.bota):

<script src="/js/vendor/base64.min.js"></script>

If the browser is newer, this script won't do anything (i.e., it won't replace the existing Window.btoa implementation). If the browser is older, it will now have the functionality.

If you want to avoid the additional HTTP request required to read base64.min.js, you can use yepnope:

yepnope({
  test: window.btoa && window.atob,
  nope: '/js/vendor/base64.js',
  callback: function () {
    // `btoa` and `atob` are now safe to use
  }
});

add this line on the header of your page, and it will be fixed

<meta http-equiv="X-UA-Compatible" content="IE=edge">
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745067252a283059.html

最新回复(0)