javascript-events

Determine what triggered focus event?

爷,独闯天下 提交于 2019-12-31 10:40:11
问题 I need to determine what caused a focus event. Ideally, I want to differentiate between a click, a tab/keyboard input, and a manual (via code) trigger. How can I do this? I'm looking at the event object, but I'm not seeing anything too useful. 回答1: If the focus comes from a $x.focus() call, then the event won't have an originalEvent property because there was no event from the browser so: if(ev.hasOwnProperty('originalEvent')) { // Focus event was manually triggered. } To differentiate

Ignore mouse interaction on overlay image

可紊 提交于 2019-12-31 05:17:11
问题 I have a menu bar with hover effects, and now I want to place a transparent image with a circle and a "handdrawn" text over one of the menu items. If I use absolute positioning to place the overlay image above the menu item, the user will not be able to click the button and the hover effect will not work. Is there any way to somehow disable mouse interaction with this overlay image so that the menu will keep on working just as before even though it's beneath an image? Edit: Because the menu

addEventListener not triggering function on click

时光怂恿深爱的人放手 提交于 2019-12-31 04:44:06
问题 the solution to this problem is probably pretty simple, but I need some help. var x; for(x in document.getElementsByTagName("img")) x.addEventListener('click',openPage, false); function openPage() { alert("clicked"); } I'm not getting an alert when I click on an <img src="something" /> tag. Anyone know why? Also, is my loop necessary? 回答1: This code produces an error - in a for..in statement, 'x' is the key of your object (in this case, your document.getElementsByTagName call). What you want

How do I capture keyboard events while watching an HTML5 video in fullscreen mode?

本秂侑毒 提交于 2019-12-31 04:29:06
问题 I need to know when the user presses the escape key when watching an HTML5 video in fullscreen mode. Unfortunately any configured listeners on the document don't apply since when the user is watching an HTML5 video in fullscreen mode the system focus is on the native video player rather than the browser. An alternative is listening for when focus reverts back from the native video player to the browser, but I'm unsure as to how I would capture this. document.addEventListener('keydown',

Javascript: cancel or let an event continue?

时光总嘲笑我的痴心妄想 提交于 2019-12-31 02:34:27
问题 My scenario deals with Kendo UI, but I think it probably applies to JavaScript generally, hence the JavaScript tag. I have a Kendo scheduler with the edit event option set to functionA. In functionA, I create a Kendo window (basically a modal) that asks the user a question; in one case the edit event should continue and bubble up as if the modal had never been there, in the other, it should prevent default and return. The problem is that the modal is non-blocking, so the confirm modal comes

javascript How to trigger native click action (replay event) later?

自古美人都是妖i 提交于 2019-12-31 02:08:46
问题 I'm using jQuery to bind to all links on the page (I'm using the 'click' event, but have tried various combinations of 'mousedown' and 'mouseup',together with bind() and live() to no avail). I can intercept the click no problem (with all the above methods). What I am trying to do is send some data via a GET request, and when it completes, allow the default click action to proceed. Since I am communicating accross-domain, I must use GET rather than POST, and so cannot make a synchronous call.

javascript How to trigger native click action (replay event) later?

这一生的挚爱 提交于 2019-12-31 02:08:05
问题 I'm using jQuery to bind to all links on the page (I'm using the 'click' event, but have tried various combinations of 'mousedown' and 'mouseup',together with bind() and live() to no avail). I can intercept the click no problem (with all the above methods). What I am trying to do is send some data via a GET request, and when it completes, allow the default click action to proceed. Since I am communicating accross-domain, I must use GET rather than POST, and so cannot make a synchronous call.

addEventListener overwrites other event actions?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-31 01:13:07
问题 Does addEventListener overwrites previously defined actions for a particular event?For example, <input type="text" name="ele" id="eleID" onfocus="doSomeThing();"/> Now if I add another action for the same event,will both both function get executed? eleID.addEventListener('focus',doSomethingElse,false); If doSomethingElse() overwrites doSomeThing() , is there any other way to do it? 回答1: No. From MDC: addEventListener is the way to register an event listener as specified in W3C DOM. Its

onclick event in select HTML not working in Safari

元气小坏坏 提交于 2019-12-30 14:56:10
问题 I have an ASP.NET dropdown list control with onclick and onchange JavaScript events. Both work in IE, Mozilla, Opera and Chrome, but not in Safari. When I remove the onclick event, onchange suddenly works. The reason I use onclick is to get the value of the dropdown list before it changes. Is there a way I can do that without using onclick ? That is, get the value of the dropdown list before it changes/a new value is selected? I want to do this in JavaScript only. 回答1: Sometimes you need to

Understanding Dean Edwards' addevent JavaScript

一曲冷凌霜 提交于 2019-12-30 10:46:22
问题 I need help understanding this piece of code. What is the point of handler.guid ? Why is there a need for a hash table? What is the point of: if ( element["on" + type]) { handlers[0] = element["on" + type]; } What does the "this" refer to in handleEvent , the element or the the addEvent function? function addEvent(element, type, handler) { // assign each event handler a unique ID if (!handler.$$guid) handler.$$guid = addEvent.guid++; // create a hash table of event types for the element if (