简体   繁体   中英

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?

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.

element.setAttribute("data-loaded", "yes")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM