Search code examples
javascriptinternet-explorercross-browserdatasetinternet-explorer-10

Javascript dataset for IE10


I don't want to be replacing all the line of code in my script where I use the property "dataset" so that it works on IE10.

I haven't found a good polyfill that actually works so I can use the following line of code:

element.dataset.loaded = "yes"

Since most of my traffic to my website uses modern browsers, I just want to implement a workaround for IE10. Any ideas or tips?


Solution

  • What really worked for me is the poliyfill html-dataset available on github. In case you are not using any framework (pure Javascript, html and css), just import via link in your html as following:

    <!doctype html>
    <html lang="en">
    <head>
      ...
      <script src="https://github.com/adamancini/html5-dataset/blob/master/html5-dataset.js"></script>
      ...
    </head>
    <body>
      ...
    </body>
    </html>
    

    In case you're using Angular or other framework, import it via polyfill,js (angular) or webpack. I tested on IE10 and worked perfectly.

    In angular 9 I just download the file and include it in the project directory and just imported it.

    import 'src/assets/polyfills/html5-dataset.js';
    

    After serve / build the project it worked too.