dom-events

How to watch for array changes?

人盡茶涼 提交于 2019-12-16 23:37:36
问题 In Javascript, is there a way to be notified when an array is modified using push, pop, shift or index-based assignment? I want something that would fire an event that I could handle. I know about the watch() functionality in SpiderMonkey, but that only works when the entire variable is set to something else. 回答1: There are a few options... 1. Override the push method Going the quick and dirty route, you could override the push() method for your array 1 : Object.defineProperty(myArray, "push"

jQuery read AJAX stream incrementally?

陌路散爱 提交于 2019-12-16 20:18:55
问题 I have read this question but it doesn't exactly answer my question. Unfortunately, it looks like things have changed in in the XHR object since I last looked at AJAX, so it is no longer possible to directly access responseText before it is finished being populated. I have to write a page that uses AJAX (preferably jQuery, but I am open to suggestions) to retrieve CSV data via HTTP from a server I have no control over. The response data could be quite large; a megabyte of text is not uncommon

Is it possible to append to innerHTML without destroying descendants' event listeners?

醉酒当歌 提交于 2019-12-16 19:25:56
问题 In the following example code, I attach an onclick event handler to the span containing the text "foo". The handler is an anonymous function that pops up an alert() . However, if I assign to the parent node's innerHTML , this onclick event handler gets destroyed - clicking "foo" fails to pop up the alert box. Is this fixable? <html> <head> <script type="text/javascript"> function start () { myspan = document.getElementById("myspan"); myspan.onclick = function() { alert ("hi"); }; mydiv =

Is it possible to append to innerHTML without destroying descendants' event listeners?

百般思念 提交于 2019-12-16 19:23:12
问题 In the following example code, I attach an onclick event handler to the span containing the text "foo". The handler is an anonymous function that pops up an alert() . However, if I assign to the parent node's innerHTML , this onclick event handler gets destroyed - clicking "foo" fails to pop up the alert box. Is this fixable? <html> <head> <script type="text/javascript"> function start () { myspan = document.getElementById("myspan"); myspan.onclick = function() { alert ("hi"); }; mydiv =

Javascript onclick event call object [duplicate]

*爱你&永不变心* 提交于 2019-12-14 03:09:17
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How do I pass the this context into an event handler? I am doing a Javascript related assignment and am required to make a calendar which is associated with a particular input. The calendar is displayed constantly and does not hide, etc. There can be multiple calendars pointing to different text fields. Now, each calendar is created by a Javascript object, i.e. var cal1=new Calendar("inputfield_id"); Now the

How to detect browser close event in Firefox?

天大地大妈咪最大 提交于 2019-12-14 02:19:02
问题 How to detect browser close event in Firefox browser? I want to do some clean up process in server side and we maintaining last logout time. To achieve this need fire an ajax call when the user clicks logout or the browser is closed. For IE the following code is working: if (window.event.clientY < 0 && (window.event.clientX > (document.documentElement.clientWidth - 5) || window.event.clientX < 0)) { logoutUser();//logging out the user } } function logoutUser(){ var xmlhttp; if (window

Slow execution of JS script

旧巷老猫 提交于 2019-12-13 21:33:56
问题 I have a simple script to toggle post image/text on onmouseover . The code works fine if there are no more than 2 posts, but it becomes VERY slow when the number of posts increases. function showPost(ele, eve) { var id = ele.id.replace("post-", ""); if (typeof window['timerHide-' + id] !== "undefined") { clearInterval(window['timerHide-' + id]); } var target = (eve.relatedTarget) ? eve.relatedTarget : eve.toElement; var parent = $("post-" + id); if (typeof target === "undefined" || target ===

How to get double click event on the Google map's marker [closed]

浪尽此生 提交于 2019-12-13 15:05:52
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 months ago . In my application, I am displaying Google map having multiple markers. In that I have click event and getting info window.But what I need is, when I double click on a marker, some other page having detailed information about that marked place should be displayed.As I will be

How can I monitor all custom events emitted in the browser?

☆樱花仙子☆ 提交于 2019-12-13 14:48:05
问题 I'd like to monitor all custom events fired within a web browser. Any standard browser will do. To be clear, I know you can attach event handlers to see when "usual" events are fired, but how can I reliably detect if an embedded object or jQuery script fires a custom event? I could refactor the browser source code to hook the event loop, but that seems rather extreme. 回答1: I'd like to monitor all custom events fired within a web browser. I don't think you can. The DOM event model works by

How to Access Dragged Text (Or: How Does Dragging Text into an Input “Work”?)

本秂侑毒 提交于 2019-12-13 14:24:50
问题 From what I've seen so far, we can use the onPaste event to validate/prevent content pasted into an <input> field. Likewise, if we want to validate/prevent a key press, we can use the onkeydown event. I'm curious about ondrag and ondrop . Specifically, how can we retrieve the content that a user drags into a text <input> ? If we wanted to grab the entire, updated input, we could just use the onchange or onblur events. However, I'm curious about grabbing just the dragged text -- similarly to