javascript-events

Is there a way track the focus on tab with Javascript?

爱⌒轻易说出口 提交于 2019-12-18 00:29:30
问题 We need to track the EFFECTIVE time on site of our users Most users, when they're done, leave the tab open and move to another tab Time on site it's extremely inaccurate Is there a Javascript Event to track the "loss of focus" of the current tab ? 回答1: This should work both on tab switch and on browser window losing focus: function onBlur() { document.body.className = 'blurred'; }; function onFocus(){ document.body.className = 'focused'; }; if (/*@cc_on!@*/false) { // check for Internet

addEventListener in Canvas tag

孤者浪人 提交于 2019-12-17 23:46:17
问题 I have a canvas tag to create a graphic. At each section of my line, I have a "dot" to enable a 'mouseover' and display more detail. Everything works fine when I don't add an event listener to this dot. Firebug is warning me : s.addEventListener is not a function... Is it possible to create dynamic event listener? (I'm new to Javascript) 回答1: You cannot attach DOM events to things other than DOM objects (elements). The canvas is a DOM element, the things you are drawing to the canvas are not.

How to check if element has click handler? [duplicate]

梦想与她 提交于 2019-12-17 23:18:36
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: test if event handler is bound to an element in jQuery Tried to do the following (link is jQuery object of 'a' tag): link.data("events") //undefined even if link has event handlers jQuery.data(link, 'events') //undefined always also jQuery._data(link, 'events') //undefined always also using jquery-1.8.3 So, how to check if element has click handler? 回答1: You can use jQuery._data to check for events. The first

javascript/DOM event name convention

允我心安 提交于 2019-12-17 23:09:37
问题 Hi when I started doing web development, I realized javascript event names were all in lower case with no separators, i.e. "mousedown" , "mouseup" , etc. And when working with the jQuery UI library, I noticed they also use the same convention; i.e. "dropdeactivate" as in the following example javascript $( ".selector" ).on( "dropdeactivate", function( event, ui ) {} ) While this works well for names that are only 2 or 3 words, it is really awful for names with more words on it. Despite of

Setting attribute disabled on a SPAN element does not prevent click events

半腔热情 提交于 2019-12-17 22:39:29
问题 I have a <span> element which does something on a click event. When I disable it, using jQuery: $("span").attr("disabled", true); The event handler continues to be called when I click on the span element. I am testing in Chrome 13. Any thoughts? 回答1: Try this: $("span").css("pointer-events", "none"); you can enabled those back by $("span").css("pointer-events", "auto"); 回答2: The disabled attribute is not global and is only allowed on form controls. What you could do is set a custom data

Add event handler for body.onload by javascript within <body> part

a 夏天 提交于 2019-12-17 22:26:58
问题 We want to include a maps from Google Maps API in our document. The documentation tells to initialize the map with a function called by the onload() event of the body. The ordinary way to call: <body onload="initialize_map();"> This doesn't work out for us because we're using Template::Toolkit and the <body> tag is already included in our wrapper. In short: The <body> tag is already printed when our javascript code starts running. I tried something like this but it does only work for onclick

How can I only allow shift+enter to return new line in text area?

末鹿安然 提交于 2019-12-17 22:17:51
问题 In a default behavior, the textarea "press" enter will become new line, but I don't want to having a new line, I want the user press "shift+enter", instead. How can I do so? or... ...can I return the textarea enter event before it actually fire to the text area?? Thank you. 回答1: $("textarea").keydown(function(e){ // Enter was pressed without shift key if (e.keyCode == 13 && !e.shiftKey) { // prevent default behavior e.preventDefault(); } }); Try the jsFiddle. 来源: https://stackoverflow.com

Allow just one click in class JQUERY

喜你入骨 提交于 2019-12-17 21:16:43
问题 I have a link that will load via ajax some content. My problem is, I don't want to remove the text "Load comments", I just want to not allow more clicks in this class. <a href="javascript:;" class="showcomments" id="'.$idf.'">Load comments</a> Jquery var Progressajax = false; $(function() { $(".showcomments").click(function(){ if(Progressajax) return; Progressajax = true; var element = $(this); var id = element.attr("id"); Progressajax = false; alert("ok"); $(data).hide().prependTo('.varload'

safari extension beforeload event documentation

╄→гoц情女王★ 提交于 2019-12-17 20:39:07
问题 I can't find any documentation on the "beforeload" event other than the Blocking Unwanted Content section of this. What I'm specifically looking for is the event message structure. From the above doc I know that there is a "event.url" member, but not much else. From a snip of source code I know there's also a "event.target.nodeName" member. But I don't have anything more than that. I got lost in both the WebKit docs and w3 event docs. Where can I find some simple reference documentation for

jQuery - convert .live() to .on()

故事扮演 提交于 2019-12-17 20:36:19
问题 How do I go about combining this old jQuery code into the v1.7 .on() ? v1.3 .live() : $('#results tbody tr').live({ mouseenter: function () { $(this).find('.popup').show(); }, mouseleave: function () { $(this).find('.popup').hide(); } }); v1.7 .on() : $('#results tbody').on('mouseenter', 'tr', function () { $(this).find('.popup').show(); }); $('#results tbody').on('mouseleave', 'tr', function () { $(this).find('.popup').hide(); }); I want to pass both event handlers to one .on() call, but