dom-events

How to display a confirmation dialog when clicking an <a> link?

岁酱吖の 提交于 2019-12-17 04:12:08
问题 I want this link to have a JavaScript dialog that asks the user “ Are you sure? Y/N ”. <a href="delete.php?id=22">Link</a> If the user clicks “Yes”, the link should load, if “No” nothing will happen. I know how to do that in forms, using onclick running a function that returns true or false . But how do I do this with an <a> link? 回答1: Inline event handler In the most simple way, you can use the confirm() function in an inline onclick handler. <a href="delete.php?id=22" onclick="return

How to display a confirmation dialog when clicking an <a> link?

前提是你 提交于 2019-12-17 04:11:59
问题 I want this link to have a JavaScript dialog that asks the user “ Are you sure? Y/N ”. <a href="delete.php?id=22">Link</a> If the user clicks “Yes”, the link should load, if “No” nothing will happen. I know how to do that in forms, using onclick running a function that returns true or false . But how do I do this with an <a> link? 回答1: Inline event handler In the most simple way, you can use the confirm() function in an inline onclick handler. <a href="delete.php?id=22" onclick="return

How to know whether refresh button or browser back button is clicked in Firefox [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-17 03:55:50
问题 This question already has answers here : detect back button click in browser [duplicate] (6 answers) Closed 5 years ago . How to know in Firefox whether refresh button is clicked or browser back button is clicked... for both events onbeforeunload() method is a callback. For IE I am handling like this: function CallbackFunction(event) { if (window.event) { if (window.event.clientX < 40 && window.event.clientY < 0) { alert("back button is clicked"); }else{ alert("refresh button is clicked"); }

How to detect responsive breakpoints of Twitter Bootstrap 3 using JavaScript?

被刻印的时光 ゝ 提交于 2019-12-17 03:21:39
问题 Currently, Twitter Bootstrap 3 have the following responsive breakpoints: 768px, 992px and 1200px, representing small, medium and large devices respectively. How can I detect these breakpoints using JavaScript? I would like to listen with JavaScript for all related events triggered when the screen change. And to be able to detect if the screen is for small, medium or large devices. Is there something already done? What are your suggestions? 回答1: Edit: This library is now available through

Get event listeners attached to node using addEventListener

匆匆过客 提交于 2019-12-17 02:59:39
问题 I have already looked at these questions: How to find event listeners on a DOM node when debugging or from the JavaScript code? can I programmatically examine and modify Javascript event handlers on html elements? How to debug JavaScript/jQuery event bindings with Firebug (or similar tool) however none of them answers how to get a list of event listeners attached to a node using addEventListener , without modifying the addEventListener prototype before the event listeners are created.

Prevent onmouseout when hovering child element of the parent absolute div WITHOUT jQuery

白昼怎懂夜的黑 提交于 2019-12-17 02:33:46
问题 I am having trouble with the onmouseout function in an absolute positoned div. When the mouse hits a child element in the div, the mouseout event fires, but I do not want it to fire until the mouse is out of the parent, absolute div. How can I prevent the mouseout event from firing when it hits a child element WITHOUT jquery. I know this has something to do with event bubbling, but I am having no luck on finding out how to work this out. I found a similar post here: How to disable mouseout

Browser event when downloaded file is saved to disk

China☆狼群 提交于 2019-12-17 02:31:34
问题 I have sensitive files to download to users, and each user is permitted to download a given file exactly once. If the download fails, I want to permit the re-download, but not otherwise. It's not sufficient to rely on logging/processing the file download request at the server - I need to know deterministically when the file is complete and in place at the client, since many of my users work in an environment with frequent connectivity drops. The most straightforward way for this to work would

On Text Highlight Event?

允我心安 提交于 2019-12-17 02:29:10
问题 I'm curious if anyone knows how I would trigger a function to run if/once the user finishes selecting text on the web page? I would like the user to be able to select text, and after a short delay(or immediately, at this point it doesn't matter much) an overlay button appears near the text that the user can then click and I go back and run more of my code that is based on the selection. This is for a Firefox extension. A similar example that I can think of would be like in IE where you can

How does one capture a Mac's command key via JavaScript?

懵懂的女人 提交于 2019-12-17 01:39:12
问题 How does one capture a Mac's Cmd key via JavaScript? 回答1: EDIT: As of 2019, e.metaKey is supported on all major browsers as per the MDN. Note that on Windows, although the ⊞ Windows key is considered to be the "meta" key, it is not going to be captured by browsers as such. This is only for the command key on MacOS/keyboards. Unlike Shift / Alt / Ctrl , the Cmd (“Apple”) key is not considered a modifier key—instead, you should listen on keydown / keyup and record when a key is pressed and then

How to watch for array changes?

感情迁移 提交于 2019-12-16 23:39:32
问题 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"