dom-events

ExtJS : handling browser exit event (click on cross-exit)

一曲冷凌霜 提交于 2019-12-30 00:54:07
问题 I would like to know if there is any way to handle the browser exit event. For example, I would like to send a query when the user click on the cross-exit or simply close his browser. 回答1: This thread might shed some insight: http://forums.devarticles.com/javascript-development-22/how-to-stop-browser-from-closing-using-javascript-8458.html I haven't given this solution a test-run yet. But it seems possible. Here's a more in-depth discussion on the onbeforeunload event handler. http://bytes

Dynamically change background color on scroll

那年仲夏 提交于 2019-12-29 08:19:11
问题 Is there any way to change background color dynamically on scroll? For example, refer this site(https://www.samsung.com/sec/smartphones/galaxy-note9/) When you first access that site, background color is blue. While scroll down, it's color change to black smoothly. Also see this site( codepen.io/Funsella/pen/yLfAG/ ) Second site is same with first. But it's color changed at once. But first site's color is not change at once. It changed gradually related to scroll position. body { height:

Replacement for deprecated `keypress` DOM event

大憨熊 提交于 2019-12-29 01:35:30
问题 According to MDN article keypress event is deprecated: But I can't find any information elsewhere on whether we should use this event in a new projects. If we shouldn't, what is the replacement? Could somebody give an insight? 回答1: Since the event is deprecated, you should avoid using it in new code, and plan on removing it from old code. The W3C specification says this about deprecated features: Features marked as deprecated are included in the specification as reference to older

How to know when an DOM element moves or is resized

﹥>﹥吖頭↗ 提交于 2019-12-28 12:18:33
问题 I'd like to know if there is a DOM event to listen for that tells me when a DOM element moves is repositioned or is resized on the page. I am not talking about an elements being drag/dropped. An example is if a have a list of three items on a page, and I use JS to remove one of the top two list items from the page (or hide it or whatever), I'd like to attach a handler to run when the third list item gets moved up in the page. I am using jQuery, so plain javascript or jQuery answers are

document.body.appendChild(i)

江枫思渺然 提交于 2019-12-28 12:15:24
问题 I am getting error only in IE7 as document.body is null; when I debug with Microsoft script editor I am getting the error in the following line: i.e. document.body.appendChild(i) Code: function nm_eraseCookie(name){ nm_createCookie(name,"",-1) } var i=document.createElement('IMG'); i.src='//e.netmng.com/pixel/?aid=403'; i.width=1; i.height=1; document.body.appendChild(i); nm_createCookie('nm_belgacom_bt', escape('tv1=bun_intvtel;tv2=;tv3=;phone1=hbs_discoveryline;phone2=hbs_classical_line

How to listen for changes to the title element?

本秂侑毒 提交于 2019-12-28 05:14:47
问题 In Javascript, is there a technique to listen for changes to the title element? 回答1: 5 years later we finally have a better solution. Use MutationObserver! In short: new MutationObserver(function(mutations) { console.log(mutations[0].target.nodeValue); }).observe( document.querySelector('title'), { subtree: true, characterData: true } ); With comments: // select the target node var target = document.querySelector('title'); // create an observer instance var observer = new MutationObserver

How do I listen for triple clicks in JavaScript?

青春壹個敷衍的年華 提交于 2019-12-28 05:06:12
问题 If this is for a double-click: window.addEventListener("dblclick", function(event) { }, false); How can I capture a triple-click? This is for a pinned tab in Google Chrome. 回答1: You need to write your own triple-click implementation because no native event exists to capture 3 clicks in a row. Fortunately, modern browsers have event.detail , which the MDN documentation describes as: A count of consecutive clicks that happened in a short amount of time, incremented by one. This means you can

onchange event not fire when the change come from another function

元气小坏坏 提交于 2019-12-28 02:12:32
问题 I have a input text that get his value from a Javascript function (a timer with countdown). I want to raise an event when the input text is 0 ,so i am using the change eventListener. Unfortunately it doesn't seem to raise the event when the change is coming from javascript function. How can I force the change event to work, even if the change is coming from Javascript and not from the user? 回答1: From the fine manual: change The change event occurs when a control loses the input focus and its

Handle URL anchor change event in js

北慕城南 提交于 2019-12-27 10:45:12
问题 How can I write the JavaScript callback code that will be executed on any changes in the URL anchor? For example from http://example.com#a to http://example.com#b 回答1: Google Custom Search Engines use a timer to check the hash against a previous value, whilst the child iframe on a seperate domain updates the parent's location hash to contain the size of the iframe document's body. When the timer catches the change, the parent can resize the iframe to match that of the body so that scrollbars

Handle URL anchor change event in js

限于喜欢 提交于 2019-12-27 10:44:04
问题 How can I write the JavaScript callback code that will be executed on any changes in the URL anchor? For example from http://example.com#a to http://example.com#b 回答1: Google Custom Search Engines use a timer to check the hash against a previous value, whilst the child iframe on a seperate domain updates the parent's location hash to contain the size of the iframe document's body. When the timer catches the change, the parent can resize the iframe to match that of the body so that scrollbars