javascript-events

JavaScript: How to simulate change event in internet explorer (delegation)

徘徊边缘 提交于 2019-12-28 01:28:27
问题 UPDATE: (recap, fiddle and bounty) This question hasn't been getting too much attention, so I'm going to spend some rep on it. I know I tend to be overly verbose in both my answers and questions. That's why I went ahead and set up this fiddle, which is, in my view, a decent representation of the kind of code I'm currently having to use to come close to a bubbling change event. A couple of issues I'm trying to resolve: The pseudo-change event doesn't fire on a select element, unless it looses

Javascript add events cross-browser function implementation: use attachEvent/addEventListener vs inline events

主宰稳场 提交于 2019-12-28 01:05:54
问题 In order to add events we could use this simple 1st solution : function AddEvent(html_element, event_name, event_function) { if(html_element.attachEvent) //Internet Explorer html_element.attachEvent("on" + event_name, function() {event_function.call(html_element);}); else if(html_element.addEventListener) //Firefox & company html_element.addEventListener(event_name, event_function, false); //don't need the 'call' trick because in FF everything already works in the right way } or this 2nd

Javascript add events cross-browser function implementation: use attachEvent/addEventListener vs inline events

浪尽此生 提交于 2019-12-28 01:05:35
问题 In order to add events we could use this simple 1st solution : function AddEvent(html_element, event_name, event_function) { if(html_element.attachEvent) //Internet Explorer html_element.attachEvent("on" + event_name, function() {event_function.call(html_element);}); else if(html_element.addEventListener) //Firefox & company html_element.addEventListener(event_name, event_function, false); //don't need the 'call' trick because in FF everything already works in the right way } or this 2nd

Detect mousemove when over an iframe?

删除回忆录丶 提交于 2019-12-27 17:37:11
问题 I have an iframe that takes up the entire window (100% wide, 100% high), and I need the main window to be able to detect when the mouse has been moved. Already tried an onMouseMove attribute on the iframe and it obviously didn't work. Also tried wrapping the iframe in a div like so: <div onmousemove="alert('justfortesting');"><iframe src="foo.bar"></iframe></div> .. and it didn't work. Any suggestions? 回答1: If your target isn't Opera 9 or lower and IE 9 or lower you can use css attribute

How do I programmatically click on an element in JavaScript?

試著忘記壹切 提交于 2019-12-27 11:01:18
问题 In IE, I can just call element.click() from JavaScript - how do I accomplish the same task in Firefox? Ideally I'd like to have some JavaScript that would work equally well cross-browser, but if necessary I'll have different per-browser JavaScript for this. 回答1: The document.createEvent documentation says that " The createEvent method is deprecated. Use event constructors instead. " So you should use this method instead: var clickEvent = new MouseEvent("click", { "view": window, "bubbles":

What's the best way to event handle dynamically created HTML? [duplicate]

帅比萌擦擦* 提交于 2019-12-26 21:38:38
问题 This question already has answers here : Adding event listeners to dynamically added elements using jQuery [duplicate] (4 answers) Closed 5 years ago . It's very easy to event-handle when dealing with items the document has from the get go: $(document).ready(function() { $('.element-in-question').on("event", function (event) { //do what you need to do during the event }); }); My problem is how would I best deal with dynamic elements. For example, let's say I dynamically load notifications,

How can I implement a JavaScript that submit this form according to the clicket button? [duplicate]

为君一笑 提交于 2019-12-25 19:39:12
问题 This question already has answers here : Two submit buttons in one form (18 answers) Closed 5 years ago . I have the following problem that I can't solve: I have this form into an HTML table: <th width = "8.33%"> <form id="actionButton" action="salwf.do?serv=1" method="post"> <button name="accept" value="Accept" type="submit" class="acceptButton">ACCEPT ICON BUTTON</button> <button name="cancel" value="Cancel" type="submit" class="cancelButton">CANCEL ICON BUTTON</button> <button name="sap"

Javascript Execution Order - When window.location.href happens?

主宰稳场 提交于 2019-12-25 18:28:11
问题 I took a look at this is-javascript-location-href-call-is-asynchronous and this what the heck is the event loop anyway but there is no explanation of the defined behavior of href of window.location : The following is the script order in source code: 1. DOM elements 2. <script> at the bottom having doc.ready. 3.Further <script> tags. 4. doc.ready's callback goes into the CB queue because all DOM elements are available in step 1 and there are only further script tags ( This callback stays in

Delete session cookies by using Javascript

天大地大妈咪最大 提交于 2019-12-25 18:22:06
问题 I am working on a function to delete the session cookies Here is the source code: <script language="javascript"> window.onload = function () { /* $.cookie('!lithiumSSO:tomtom.stage', null); $.cookie('LiSESSIONID', null);*/ delete_cookie('LiSESSIONID'); delete_cookie('!lithiumSSO:tomtom.stage'); }; function delete_cookie ( cookie_name ) { var cookie_date = new Date ( ); // current date & time cookie_date.setTime ( cookie_date.getTime() - 1 ); document.cookie = cookie_name += "=; expires=" +

YUI3 events not working in Firefox or Opera, works fine in Chrome though

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 16:44:33
问题 I have a very simple YUI3 script which changes background of a web page. Here is the source <html> <head> <title>YUI 3 events do not work!</title> </head> <body id="doc-body"> <div id="rgbvalues"> </div> <script src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js" charset="utf-8"></script> <script type="text/javascript"> //use node and event modules YUI().use("node", "event", function(Y){ var handleClick = function(e) { var docBody = Y.one("#doc-body"); //equivalent to $(element) in