dom-events

Get bounding client rectangle without borders

白昼怎懂夜的黑 提交于 2020-01-05 06:38:05
问题 I made a function that transforms mouse coordinates to canvas pixel coordinates: /* Returns pixel coordinates according to the pixel that's under the mouse cursor**/ HTMLCanvasElement.prototype.relativeCoords = function(event) { var x,y; //This is the current screen rectangle of canvas var rect = this.getBoundingClientRect(); //Recalculate mouse offsets to relative offsets x = event.clientX - rect.left; y = event.clientY - rect.top; //Also recalculate offsets of canvas is stretched var width

prototype - Trigger event when an element is removed from the DOM

 ̄綄美尐妖づ 提交于 2020-01-04 05:25:22
问题 I'm trying to figure out how to execute some js code when an element is removed from the page: Something in prototype like: $('custom-div').observe('remove', function(event) { // Handle the event }); Does anything like this exist? 回答1: In modern browsers, you can use a MutationObserver . Here's code that will call a callback when a DOM element is removed from it's current location: function watchRemove(el, fn) { var observer = new MutationObserver(function(mutations) { mutations.forEach

How to capture printscreen event in Javascript?

落爺英雄遲暮 提交于 2020-01-04 03:14:58
问题 I'm trying to write a web application which has some sensitive content in it. I have already prevented copy-and-paste. How do I detect when someone presses the printscreen key, so that the data may be hidden when that is pressed? Do not worry about mobile phones/cameras/ screen recording software, as they are not used in the environment. 回答1: I went googling for the information and I hope the 2 links below will be able to assist you. http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread

How to capture printscreen event in Javascript?

孤街醉人 提交于 2020-01-04 03:13:11
问题 I'm trying to write a web application which has some sensitive content in it. I have already prevented copy-and-paste. How do I detect when someone presses the printscreen key, so that the data may be hidden when that is pressed? Do not worry about mobile phones/cameras/ screen recording software, as they are not used in the environment. 回答1: I went googling for the information and I hope the 2 links below will be able to assist you. http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread

Which events are attached to an element?

≯℡__Kan透↙ 提交于 2020-01-03 20:09:54
问题 How can I receive all events attached to an element with dojo? dojo.query('#mydiv') // which events does #mydiv has? 回答1: To get all events on a DOM element: // Get my div myDiv = dojo.byId("myDiv"); // Obtain all event-related attributes var events = dojo.filter( myDiv.attributes, function(item) { return item.name.substr(0, 2) == 'on'; } ); // Execute first found event, just for fun eval(events[0].value); If you get myDiv using dojo.query, remember that dojo.query returns an array, so your

Disable keyboard in HTML SELECT tag

人盡茶涼 提交于 2020-01-03 18:57:20
问题 I want to disable the keyboard for an HTML SELECT tag so the user can only use a mouse to select the options. I've tried event.cancelBubble=true on the onkeydown , onkeyup and onkeypress events with no luck. Any ideas? 回答1: In a cross-browser way assuming that the event object has been properly initialized: function disableKey(e) { var ev = e ? e : window.event; if(ev) { if(ev.preventDefault) ev.preventDefault(); else ev.returnValue = false; } } 回答2: Someone left me the correct answer and

Do not fire 'zoom_changed' event when calling fitBounds function on map

会有一股神秘感。 提交于 2020-01-03 07:25:29
问题 Is there a way to prevent the zoom_change event from being triggered if it occurs due to fitBounds() ? I am having an issue where I need to do a search on the server from client when there is a zoom change to map but every time I call fitBounds() it causes zoom_change to trigger which causes the client to do another search on the server. I am only interested in zoom_change done by users and not programmatically using fitBounds . 回答1: When you do a fitBounds in your program, set a global flag.

Better approach nulling variables, objects in Javascript

时光总嘲笑我的痴心妄想 提交于 2020-01-03 04:23:06
问题 I am building something for mobile and would like somehow to clear, null objects, variables to release a bit of memory. Here I have two quick examples, both are anonymous functions as I believe but what way is better or more valid approach? Sorry if I get it all wrong. To me both seem to do the same thing although I like more the first one as objects wont be created until I need it. The second version would immediately execute the code for creating variables, objects etc. but not doing the

dojo how to override dijit class method

天大地大妈咪最大 提交于 2020-01-02 09:12:45
问题 I need to override onClick method in the Tree.js. Is there any common way to override dojo/dijit classes methods? 回答1: You could use: dojo.connect(tree, 'onClick', function(item) { /** Your Action **/ }); 回答2: I'm a bit confused, since you were already doing this in the last question you posted. You've got a few choices, depending on what you want to do. Clobbering method stubs In the case of true stubs like onClick , it's potentially as easy as clobbering that method on your widget instance.

Why does this anchor say “search is not a function”?

筅森魡賤 提交于 2020-01-02 04:40:09
问题 I wrote a function named search that I expected to be called when the link was clicked, as the code snippet below shows: <script> function search() { console.log('Searching'); } </script> <a href="#" onclick="search();">Click here</a> However, the code does not work as I expected, which causes this error (in Chrome) when the link is clicked: Uncaught TypeError: search is not a function I tried logging search to see why the error was thrown: <a href="#" onclick="console.log(search)">Click here