window.chrome.webview.addEventListener vs. document.addEventListener

1k Views Asked by At

Which event listener is used for what?

  • window.chrome.webview.addEventListener
  • document.addEventListener

Are these synonyms or is there a difference? If yes, which?

1

There are 1 best solutions below

2
T.J. Crowder On

From your comment:

Environment: It is used for display in a Delphi Edge component. The point is, however, to understand JavaScript.

Neither of these is specifically JavaScript. They're both external APIs provided to the JavaScript environment by the host environment. (The host environment in your case is apparently a Delphi Edge web browser control. Other examples are web browsers generally, or outside that realm there's Node.js, Deno, and some others.)

Of those two:

  • The first one is specific to the Delphi Edge component you asked about (perhaps more generally to the webview control that it uses).

  • The second, document.addEventListener, is the standard DOM API method for hooking into events (in this case at the document level rather than a specific element within the document). That's provided to JavaScript running in web browsers by the browser, and is available cross-browser.

If you're looking to do standard web programming and need to hook into an event at the document level, you'd use the second.