javascript-events

Javascript: removing an anonymous event listener [duplicate]

爷,独闯天下 提交于 2019-12-18 06:18:12
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Removing an anonymous event listener I have the following cross browser function to add an event listener: _SU3.addEventListener = function(elem, eventName, fn) { if(elem.addEventListener ) { elem.addEventListener(eventName, fn, false); } else if (elem.attachEvent) { elem.attachEvent('on'+eventName, fn); } }; I'm adding the listener like this: _SU3.addEventListener(_show, "click", function(event) { _SU3

Knockout js -> Bind to editable div text?

萝らか妹 提交于 2019-12-18 05:40:15
问题 How can I bind an observable to an editable div text content? 回答1: You will need to modify the default "text" binding so that it is able to write the content of the edited div back to the observable. A simple custom binding handler for this task can look like this: ko.bindingHandlers.editableText = { init: function(element, valueAccessor) { $(element).on('blur', function() { var observable = valueAccessor(); observable( $(this).text() ); }); }, update: function(element, valueAccessor) { var

Canvas images and Click event

你说的曾经没有我的故事 提交于 2019-12-18 05:24:10
问题 I have currently two circles in a <canvas> tag with HTML5 & JavaScript. Now I'm trying to add an image (done) that changes based on mouse-over and click. It's basically an implementation of a play / pause button with an extra color change when the user mouse-overs the button. I can't seem to figure out how events work on shapes in HTML5 since they are not objects ... Here is my code at the moment : window.onload = function() { var canvas = document.getElementsByTagName('canvas')[0]; var

detachEvent not working with named inline functions

老子叫甜甜 提交于 2019-12-18 05:18:23
问题 I ran into a problem in IE8 today (Note that I only need to support IE) that I can't seem to explain: detachEvent wouldn't work when using a named anonymous function handler. document.getElementById('iframeid').attachEvent("onreadystatechange", function onIframeReadyStateChange() { if (event.srcElement.readyState != "complete") { return; } event.srcElement.detachEvent("onreadystatechange", onIframeReadyStateChange); // code here was running every time my iframe's readyState // changed to

setting oninput event with Javascript

痞子三分冷 提交于 2019-12-18 04:38:06
问题 The HTML5 "oninput" event is supported by some modern browsers, including Firefox 3.X However, strangely, it only seems to work with inline javascript: <input id = "q" oninput="alert('blah')"> When I try to set it using javascript code, it doesn't fire. var q = document.getElementById("q"); q.oninput = function(){alert("blah");}; Is this just a bug in Firefox, or is there some reason this happens? 回答1: After downloading FireFox v3.6.27 and doing some test and search. I found my previous

Is dispatchEvent a sync or an async function

核能气质少年 提交于 2019-12-18 04:37:11
问题 I am trying to write an event handler for a custom event in WinJS. I am not too sure how this works in IE - I am creating a custom event and dispatching it - var eventObject = document.createEvent("CustomEvent"); eventObject.initCustomEvent("dropbomb", true, true, null); this._element.dispatchEvent(eventObject); My handler is - this._element.addEventListener("logtelemetry", function () { console.log("boom"); }); Can I be certain that the handler will be called in sync and not at a later time?

Javascript: cross-domain window.close event from parent window

痴心易碎 提交于 2019-12-18 04:25:17
问题 For example i'm on domain1: a.click(function(){ window.win=window.open(domain2,'name'); }); Now i'm on domain2 and i'm closing it. How does window.win will know that user closed that window? Is there any event or property to check via interval? 回答1: There is a property which is not part of any W3C spec. It's called closed and would get accessed like if( window.win.closed ) { // window was closed } I'm not sure about the cross-browser compatibilty for that property. I'm also not sure how this

Stop form submission with submit eventlistener

核能气质少年 提交于 2019-12-18 04:21:39
问题 I'm trying to stop a form from submitting using the submit eventlistener. My anonymous function runs but the form still submits, even with return false at the end of the function. There are no JS errors being thrown. Am I making some stupid mistake? <form id="highlight"> Row: <input type="text" name="rows" value="1" id="rows"> Column: <input type="text" name="cells" value="1" id="cells"> <input type="submit" name="Submit" value="Highlight" id="Submit"> </form> <script> var highlight_form =

Stop form submission with submit eventlistener

£可爱£侵袭症+ 提交于 2019-12-18 04:21:13
问题 I'm trying to stop a form from submitting using the submit eventlistener. My anonymous function runs but the form still submits, even with return false at the end of the function. There are no JS errors being thrown. Am I making some stupid mistake? <form id="highlight"> Row: <input type="text" name="rows" value="1" id="rows"> Column: <input type="text" name="cells" value="1" id="cells"> <input type="submit" name="Submit" value="Highlight" id="Submit"> </form> <script> var highlight_form =

Capture all the events (javascript)

蹲街弑〆低调 提交于 2019-12-18 04:09:08
问题 I want to be able to capture all events that are both created and dispatched and fire some callback when that happens. Also, I would like to be able to fire a callback anytime an event is paired with an event listener. Problems include: dynamically added elements, events whose propagation or bubbling is prevented, and custom events that are generated dynamically. I imagine there would need to be a prototyping of dispatchEvent or something, but I am unsure. Is this even possible? 回答1: Some