javascript-events

Dynamic Script Tag Addition is Asynchronous?

夙愿已清 提交于 2019-12-23 10:26:33
问题 Is Dynamic Script Tag Addition is Asynchronous? Like dynamically including set of JavaScript files from a different domain.. 回答1: Yes, it is asynchronous. Dynamic <script> injection always results in the browser loading an external resource via the DOM (e.g. just like stylesheets, images, flash), which must happen asynchronously to avoid browser lockup. Are you looking at JSONP ("JSON with Padding") by any chance? It uses dynamic script tag injection. It's more and more part of discussions

Propagating mouse events from iframes to the hosting document

痞子三分冷 提交于 2019-12-23 10:13:38
问题 I have an iframe covering the entire HTML document, and I'd like to propagate clicks and hover events back to the hosting document. What are my options? 回答1: I was asked to look into this several weeks ago for a project. It's possible to do it, and there's a working example of it in action here: http://www.esqsoft.com/javascript_examples/iframe_talks_to_parent/ However, the crucial thing to bear in mind is that unless the parent and child are on the same domain, it's not possible to have

Trigger Real Event with jQuery

喜夏-厌秋 提交于 2019-12-23 09:37:24
问题 It seems that jQuery's trigger() only runs event handlers that were bound with jQuery. I have some modules that use native browser event binding. Using the code from https://stackoverflow.com/a/2676527 works for me, but I'm wondering if there's something built in to jQuery that will do this? Update from comments: apparently it works for click events on buttons. But not for change events on select boxes: http://jsfiddle.net/qxpXV/2/ For the record: hacking the other library to do its bindings

accessing mutable variable in an event closure

对着背影说爱祢 提交于 2019-12-23 09:30:17
问题 I am trying to use the mousetrap javascript plugin to handle some key strokes in a similar fashion, so I thought to code them up as follows: var keys = [ 'b', 'i', 'u']; for (var i=0; i < 3; ++i) { var iKey = keys[i]; var iKeyUpper = iKey.toUpperCase(); Mousetrap.bind( [ 'command+' + iKey, 'command+' + iKeyUpper, 'ctrl+' + iKey, 'ctrl+' + iKeyUpper], ( function( e ) { console.log( "you clicked: " + i ); } ) ); } But, obviously, i is mutable. However, I am not sure how to write a closure where

onfocus is not called when using the autofocus attribute on an input tag

余生颓废 提交于 2019-12-23 09:20:05
问题 In the following example, I get only one alert box. I read that the focus is put before the JavaScript code is executed. Is there a way to get this to work on? <input id="i" type="text" autofocus onfocus="alert(1)"> <script type="text/javascript"> document.getElementById('i').addEventListener('focus', function() { alert(2); }, false); </script> (I have only tested this in Safari) Edit: I can obviously do it this way (Prototypejs selector): var autofocusElement = $$('input[autofocus]')[0];

addEventListener not working in Chrome

懵懂的女人 提交于 2019-12-23 08:57:07
问题 I am following a tutorial on Lynda.com about the new DOM event model. This is the code I am working with. function addEventHandler(oNode, sEvt, fFunc, bCapture){ if (typeof (window.event) != "undefined") oNode.attachEvent("on" + sEvt, fFunc); else oNode.addEventListener(sEvt, fFunc, bCapture); } function onLinkClicked(e){ alert('You clicked the link'); } function setUpClickHandler(){ addEventHandler(document.getElementById("clickLink"), "click", onLinkClicked, false); } addEventHandler(window

Listen to jQuery event without jQuery

拟墨画扇 提交于 2019-12-23 08:29:12
问题 Is there a way to set up an event listener, so it captures an event fired by jQuery? I want to use only plain (vanilla) JavaScript to listen to the event. I have set up the following example: (function($) { $(document).on('sent_jquery_rec_jquery', function () { console.log('sent_jquery_rec_jquery'); }); $(document).on('sent_vanilla_rec_jquery', function () { console.log('sent_vanilla_rec_jquery'); }); document.addEventListener('sent_vanilla_rec_vanilla', function () { console.log('sent

Show mouse x and y position with javascript

余生长醉 提交于 2019-12-23 08:00:09
问题 First version does not show me x and y and get I get following error: Uncaught TypeError: Cannot read property 'pageX' of undefined The Second version works but is very similar coded, can't find the problem. FIRST VERSION (NOT WORKING) <form name ="show"> <input type="text" name="mouseXField" value="0" size="6">Mouse X Position<br> <input type="text" name="mouseYField" value="0" size="6">Mouse Y Position<br> </form> <script type="text/javascript"> var mie = (navigator.appName == "Microsoft

How do I detect a jquery trigger events completion?

拜拜、爱过 提交于 2019-12-23 07:56:20
问题 I'm trying to trigger a second event dependent on the first like so: ... $('#productFamilyId').val(data.contents.productfamily); $('#productFamilyId').trigger('change', function() { $('#productId').val(data.contents.product); $('#productId').trigger('change'); }); It's not waiting for the first trigger to complete before attempting to trigger the second event. Is it possible to wait for the first trigger to complete? 回答1: There is no callback for the trigger method. The extra parameters are

addEventListener in jQuery [duplicate]

≯℡__Kan透↙ 提交于 2019-12-23 07:47:53
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: jQuery equivalent of JavaScript's addEventListener method Also from a very good jQuery tutorial on : http://itunes.apple.com/in/app/designmobileweb/id486198804?mt=8 What is the jQuery equivalent for the following statement; element1.addEventListener('click',doSomething2,false) If it is the bind() method, is there any option to specify the last parameter (i.e. event bubbling or capturing ...true/false) Thank you.