dom-events

Clone a DOM event object to re-dispatch

北城以北 提交于 2020-01-12 14:32:12
问题 Some browsers won't allow you to re-dispatch an event that has already been dispatched, but allow you to create new event objects based on values that can be obtained from the existing event object. Is there a generic and reusable solution that will work with any event type, or failing that, a way to do this for a specific event type (in my case I'm currently concerned with the mousewheel event)? 回答1: It seems there is now an even better solution, since initMouseEvent and the like are

Clone a DOM event object to re-dispatch

怎甘沉沦 提交于 2020-01-12 14:31:10
问题 Some browsers won't allow you to re-dispatch an event that has already been dispatched, but allow you to create new event objects based on values that can be obtained from the existing event object. Is there a generic and reusable solution that will work with any event type, or failing that, a way to do this for a specific event type (in my case I'm currently concerned with the mousewheel event)? 回答1: It seems there is now an even better solution, since initMouseEvent and the like are

Why does a `click` event get triggered on my <button> when I press Enter on it?

﹥>﹥吖頭↗ 提交于 2020-01-12 13:52:34
问题 I'm only adding a click event handler on my <button> . document.getElementsByTagName("button")[0].addEventListener("click", event => { event.preventDefault(); console.log("Click:", event); }); <button>Press <kbd>Enter</kbd> on me</button> (Demo link) Nevertheless, when I tab to the button in Firefox, then press Enter , I see the click event being fired. However, I cannot see this behaviour documented anywhere. Is this standard behaviour, and can I count on it working in all browsers? 回答1:

Why does a `click` event get triggered on my <button> when I press Enter on it?

那年仲夏 提交于 2020-01-12 13:50:54
问题 I'm only adding a click event handler on my <button> . document.getElementsByTagName("button")[0].addEventListener("click", event => { event.preventDefault(); console.log("Click:", event); }); <button>Press <kbd>Enter</kbd> on me</button> (Demo link) Nevertheless, when I tab to the button in Firefox, then press Enter , I see the click event being fired. However, I cannot see this behaviour documented anywhere. Is this standard behaviour, and can I count on it working in all browsers? 回答1:

Stop Javascript Function execution from another Function

不打扰是莪最后的温柔 提交于 2020-01-12 07:32:06
问题 Is there any way to stop the execution of a called function from another function? I have following code:- function MainFunction() { //a long code that runs for few time }; MainFuntion(); <button onclick="(Here I want some thing to stop MainFunction())">Stop the running script </button> so basic idea is to return a function from another function 回答1: JavaScript is normally single threaded - meaning that while a function is executed in the browser no other code can run at the same time -

Set style change event listener in Javascript

泄露秘密 提交于 2020-01-11 13:59:07
问题 My div looks something like this: <div tabindex="0" role="button" id="profile-pic" style="background-image: "Some url";"></div> The background image will be updated based on some criteria. I want to set listener to the style property and listen to background image change. Is it possible? 回答1: You can use MutationObserver Then code example: var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutationRecord) { console.log('style changed!'); }); }); var target =

Does Javascript event queue have priority?

天涯浪子 提交于 2020-01-11 02:07:17
问题 These days, I have read some documents about setTimeout, setInterval. I have learned that the Javascript is a single thread which will only execute one piece of code per time. At the same time, if there is a event happens, it will be pushed into the event queue and block until appropriate time. I want to to know, when many events are blocked waiting to execute at the same time. Is these events have different priorities, so the high priority event will execute before the low ones. Or just a

Get value of multiselect box using jQuery or pure JS

主宰稳场 提交于 2020-01-09 06:50:29
问题 In the code shown below, how to get the values of multiselect box in function val() using jQuery or pure JavaScript? <script> function val() { //Get values of mutliselect drop down box } $(document).ready(function () { var flag = 0; $('#emp').change(function () { var sub = $("OPTION:selected", this).val() if (flag == 1) $('#new_row').remove(); $('#topics').val(''); var html = '<tr id="new_row" class="new_row"><td>Topics:</td><td> <select id="topic_l" name="topic_l" class="topic_l" multiple=

The mousemove event throws error in angular

大兔子大兔子 提交于 2020-01-06 07:20:52
问题 I am trying to calculate the top and left of *ngfor elements wrt to parent element The mousemove function throws me an error. I tried referencing the parent element to capture the mousemove private elem; private container; private mouse = { x: null, y: null, down: false }; private will_draw = false; @ViewChild('parentcontainer') flo; ngAfterViewInit() { this.elem = this.elRef.nativeElement.querySelector('box'); this.container = this.elRef.nativeElement.querySelector('dropzone'); }

Detecting tab closed (after closed) from Firefox extension

时光毁灭记忆、已成空白 提交于 2020-01-05 10:32:02
问题 I'm trying to get my Firefox extension to create a url list from all tabs in the browser. To keep the list updated I need to know when a tab has been closed. I've tried using: window.addEventListener("TabClose", tabRemoved, false); However, this gets called BEFORE the tab is actually closed, which results in my updated tablist still containing the closed tabs url. I update the tab list by iterating all browsers, like so: function () { gBrowser = window.getBrowser(); tabs = gBrowser.browsers;