Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to composedPath for Edge

I would like to be able to detect the path when I click somewhere using Edge/IE. With all other browsers I can use event.composedPath(), but Edge and IE don't support it.

I've been looking around and I only found pages discouraging from using path and using composedPath() instead, but I didn't find any reference for Edge.

Help, please!

like image 605
xavier Avatar asked Nov 21 '25 02:11

xavier


1 Answers

You can try to check this polyfill may help to get composed path.

// Event.composedPath
(function(e, d, w) {
  if(!e.composedPath) {
    e.composedPath = function() {
      if (this.path) {
        return this.path;
      } 
    var target = this.target;

    this.path = [];
    while (target.parentNode !== null) {
      this.path.push(target);
      target = target.parentNode;
    }
    this.path.push(d, w);
    return this.path;
    }
  }
})(Event.prototype, document, window);

use it like below:

var path = event.path || (event.composedPath && event.composedPath());

References:

(1) event.path undefined with Firefox and Vue.js

(2) rockinghelvetica/composedpath.polyfill.js

Other than that I did not got any alternative or work around to get Event.Composedpath for IE and Edge browsers.

like image 171
Deepak-MSFT Avatar answered Nov 22 '25 16:11

Deepak-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!