Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Increase the ability to query whether the host environment supports a specific event #968

Open
answershuto opened this issue Apr 13, 2021 · 8 comments

Comments

@answershuto
Copy link

We hope to solve the problem of obtaining whether the current host environment itself provides a certain event capability according to the "feature judgment" under the Web standard, so as to know whether a specific event capability can be used in the current host environment.

for example:

Take the dblclick as an example. On the mobile terminal, browsers such as safari and firefox support it, but chrome and android WebView do not. At this time, if we don't have "feature judgment", we need to code like the following.

if (/Chrome/.test(window.navigator.userAgent)) {
  // Realize by other means, such as judging 2 clicks
} else {
  element.addEventListener('dblclick', (e)=>{
    //...
  });
}

Obviously, we can implement related functions through "environmental judgment", but when the historical version and the variety of browsers bring a lot of judgment conditions.

We expect to expand on eventTarget to solve this problem.

More detailed content - https://github.com/answershuto/isEventSupports.

@annevk
Copy link
Member

annevk commented Apr 13, 2021

The way this is down is through event handler attributes, e.g., "ondblclick" in element. Why is that not sufficient?

@answershuto
Copy link
Author

answershuto commented Apr 13, 2021

The reason is explained in this document.

https://github.com/answershuto/isEventSupports#other-considerations

@WebReflection
Copy link

WebReflection commented Apr 13, 2021

@answershuto

At this time, input will return true normally, but in fact there will be no input event on the div.

This is quite random ... as soon as the div has contentEditable set to true, or as attribute, it supports input events.

Any other concrete example that wouldn't fail expectations? 'cause divs do support input events.

@annevk
Copy link
Member

annevk commented Apr 13, 2021

@answershuto I read that, but DOM0 and DOM2 no longer exist so I don't really see how that applies in today's world.

@answershuto
Copy link
Author

@WebReflection What about onload ?

@answershuto
Copy link
Author

If 'onxxxx' in window is used for detection, can 'onxxxx' ensure one-to-one correspondence with supported events?

@annevk
Copy link
Member

annevk commented Apr 13, 2021

Generally we try to maintain that, yes. Of course, sometimes with elements onx could be true, but events of that name don't get dispatched on that element (yet), but I don't think we've run into a problem in practice with that.

@WebReflection
Copy link

@answershuto what about it?

const div = document.createElement('div');
div.addEventListener('load', console.log, true);
document.body.appendChild(div).innerHTML = '<img src="/favicon.ico">';

Works pretty well to me.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

3 participants