javascript-events

Firing change events in Selenium and IEx?

感情迁移 提交于 2019-12-14 01:19:54
问题 I'm just getting started on Selenium, so I'm still wrapping my head around all the moving parts. I've got my first test suite up and running, but can't for the life of me get jQuery event listeners to fire in IE. This is especially problematic on dynamic AJAX dropdowns such as $('#country').live('change',showStates) select -> id=country | label=United States The selenium driver triggers the events in response to the test script for all other browsers, but nothing I've tried causes or forces

How to do an action only when there is no default in Javascript / jQuery?

徘徊边缘 提交于 2019-12-14 01:19:18
问题 I'm asked that a click anywhere in a div does a specific action (say collapse it) unless the click was on a link, a button, etc... Basically, I'd like the reverse of event.preventDefault() . Is there a good and easy way to do this? I'm looking for a generic solution here; I would like to not assume much about the content of the div. Might look like: <div id="click_me> <p>Clicking here should do stuff <a href="http://stackoverflow.com">but not here, nor on the following image</a> <a href="/xyz

Catch / Listen to function's execution

一曲冷凌霜 提交于 2019-12-14 01:18:17
问题 I want to add to all functions in module logger. I want to log "start" time of the function and "end" time. So that's way I can get performance time of every function (sync functions). But I can't get how to make it work.. =( I don't want to rewrite functions in some dynamic way - I want to debug them in the future..So need to keep original code - I need to find some way to wrap every function... Lets take a look some example: module.exports = { someVar: "12345string", operation1: function(){

javascript blur event — is there any way to detect which element now has focus? [duplicate]

房东的猫 提交于 2019-12-14 00:48:18
问题 This question already has answers here : When a 'blur' event occurs, how can I find out which element focus went *to*? (23 answers) Closed 6 years ago . Does anyone have a technique that will allow me to determine which element has focus after a blur event? I have an input field which I'd like to reset on blur unless the blur was caused by the user clicking the "save" button. I'd love to just set a flag in the save button's onclick function, but that would fire too late (unless click events

Set focus on web page rather than Firefox debugger after refreshing page

萝らか妹 提交于 2019-12-14 00:35:52
问题 I'm using the default Firefox web developer tools. Firefox 20.0, Mac OS X 10.7. If I have the developer tools' Debugger panel open (but not focussed), and refresh the page, focus goes to the debugger panel rather than the refreshed page. Can I set focus to go to the refreshed page instead? If I have the Web Console panel open instead, that doesn't steal the focus - ideally I'd like to get the debugger to behave the same way. My program uses document keyup and keydown events, and the page

capture the result of window.onbeforeunload

帅比萌擦擦* 提交于 2019-12-13 22:23:15
问题 I have a scenario, I have to save the changes when user clicks yes on window.onbeforeunload for that I need to submit the form and nothing should be happen when selected no. Any help is greaty appreciated I have tried this window.onbeforeunload= function(){ var r = confirm("Are you sure you want to leave this page?"); if (r == true) { readForm.action = '/SREPS/read.do' ; readForm.submit(); }else{ return false; } } It did not worked 100% when ever we hit Cancel during window.confirm another

Playing a video when clicking on an element of an image.

南楼画角 提交于 2019-12-13 18:06:20
问题 I want to know if it's possible to play a video when you click on an element of an image, and play another video if you click on another element of the same image ? For instance, imagine a picture of a room : - if I click on the area where the TV set is, the image disappears and video1 starts. - if I click on the chair, same thing but video2 starts instead. Is this possible using HTML5 and Javascript? If so, how am I going to do that ? Thanks a lot for reading ! 回答1: Yes, it is possible. I'm

How do I change the Javascript src file on client side?

筅森魡賤 提交于 2019-12-13 17:28:31
问题 Within my body tag, I have this: <script src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAkh87y8Hjhg76ty" type="text/javascript"></script> Is it possible to add Javascript or jQuery in the head of the page to change the "key" parameter in the script source. I am trying to do this before the render reaches the above tag. 回答1: It is not possible to change the src attribute before the render reaches the tag, because modern browsers will download and parse the script as soon as it

input fill with keypress simulation

人走茶凉 提交于 2019-12-13 17:12:13
问题 Let's say we have an input and we want to add some texts to it. <form> First name:<br> <input type="text" id="thename" name="firstname"> </form> The simple thing is to add value to input with classic element.value... . But what if I want to add for example 'David' by simulating the keypress event? I followed several approaches like this: function simulateKeyEvent(character) { var evt = document.createEvent("KeyboardEvent"); (evt.initKeyEvent || evt.initKeyboardEvent)("keypress", true, true,

How to add two values in javascript

别来无恙 提交于 2019-12-13 17:09:34
问题 This is a simple dropdown with values. I'm trying to pull the values as currency then add. The values aren't being added ( 1+1=2 or 1+2=3 ) but instead are concatenating ( 1+1=11 or 1+2=12 ). Where am I going wrong here?: <script> function displayResult() { var strm=document.getElementById("matt").options[document.getElementById("matt").selectedIndex]; var t=strm.text.search("\\\$"); var strb=document.getElementById("box").options[document.getElementById("box").selectedIndex]; var b=strb.text