javascript-events

how to disable the function of ESC key in JavaScript?

会有一股神秘感。 提交于 2019-12-21 05:42:13
问题 In my chat application there are some text fields which gets the user login details. when filling the user details,If user suddenly pressed the ESC key,the data will be lost. I need to disable the function of ESC key ? which event I need to use ? how can I do that. my Java Script code is , function esc(e){ e = e || window.event || {}; var charCode = e.charCode || e.keyCode || e.which; if(charCode == 27){ return false; } } Searched a lot in Stack overflow and google.Nothing worked.Please any

How can I check that a key has been pressed?

只谈情不闲聊 提交于 2019-12-21 05:27:19
问题 Well I searched on google but still didn't found the answer I was looking for. I want to check if the user pressed a key, something like this - if(document.onkeyup) { // Some Stuff here } I know I can do this, this way - document.onkeyup = getKey; But the function getKey cannot return values. So how can I check if the user pressed a key? EDIT : I need pure javascript for this thing.. 回答1: You can do this in pure Javascript using the event object, without the need of external libraries such as

jQuery multiple click event

有些话、适合烂在心里 提交于 2019-12-21 05:24:14
问题 I'm forced to use a script loaded from an external server. This script basically adds an element <div class="myClass"> and bind a click method to it. The thing is, in the click function associated to the element, they have a return false statement at the end. I also have my own script and I'm trying to add a click method to the same element using $(document).on('click', '.myClass', function() { ... }) My problem is that their event is triggered before and the return false in their function

Trying to configure YouTube subscribe button callbacks

China☆狼群 提交于 2019-12-21 05:15:09
问题 Below is the snippet of the code which I have tried. <script src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> function onYtEvent(payload) { if (payload.eventType == 'subscribe') { // Add code to handle subscribe event. alert("hello world") }); } else if (payload.eventType == 'unsubscribe') { // Add code to handle unsubscribe event. alert("asdf"); } if (window.console) { // for debugging only window.console.log('YT event: ', payload); } } </script> <div

How to know if there is any Ajax Request and ajax Success

落花浮王杯 提交于 2019-12-21 04:34:34
问题 I wonder how can I code this //if there is any ajax request $("#loader").css("display","block"); //on success: $("#loader").css("display","none"); Note : i am not going to code it again and again in my each ajax request function. i want it Genric. so that my script knows if there is any ajax request do $("#loader").css("display","block"); and if there is any ajax success do $("#loader").css("display","none"); 回答1: The magical thing you are looking for is jQuery.ajaxStart() and jQuery.ajaxStop

Problems refreshing angularjs changes on production server

折月煮酒 提交于 2019-12-21 04:34:22
问题 I have a recurring issue that occurs when I make changes to my angularjs app. The problem is that I have to refresh the page if I want to seed the changes that I have made. This is a problem, because I don't want my users to have to refresh the page (they may not know to do this). They may think the site is broken. Is there some kind of angular directive or process that I can follow that will allow my UI changes to be reflected on my production server without my users having to refresh the

How to return multiple arrays from a function in Javascript?

房东的猫 提交于 2019-12-21 04:11:12
问题 I have multiple arrays in a function that I want to use in another function. How can I return them to use in another function this.runThisFunctionOnCall = function(){ array1; array2; array3; return ???? } 回答1: as an array ;) this.runThisFunctionOnCall = function(){ var array1 = [11,12,13,14,15]; var array2 = [21,22,23,24,25]; var array3 = [31,32,33,34,35]; return [ array1, array2, array3 ]; } call it like: var test = this.runThisFunctionOnCall(); var a = test[0][0] // is 11 var b = test[1][0]

javascript extension to use C based APIs(clutter) in a webapp

烈酒焚心 提交于 2019-12-21 03:42:28
问题 My goal is to use the C libraries to form web apps. I have choosen the way to do that via using "SWIG" tool. The Swig tool requires three things 1) .c file which defines all the functions. 2) .i file also called interface file which is creating the interface to load the APIs wherin I used the extern keyword. 3) APP written in javascript extension (.js file). I used SWIG tool to compile and run this app to verify the .js file has made correctly. The application is running fine on XMING X11

can't fire keypress event when press delete key

坚强是说给别人听的谎言 提交于 2019-12-21 03:32:09
问题 I'm finding that the delete key doesn't fire the keypress event in Chrome, while other keys work. The problem doesn't occur in Firefox, just in chrome, why? Here is my code: document.addEventListener('keypress', function (e) { console.log(e); }, false); 回答1: Use keydown or keyup instead, it captures the delete key (as well as others that keypress doesn't, see http://www.quirksmode.org/js/keys.html) document.addEventListener('keydown', function (e) { console.log(e); }, false); 回答2: keypress

Chrome Extension - first link is auto-focused in popup

南笙酒味 提交于 2019-12-21 03:31:06
问题 How do I stop my Google Chrome extension's default action to auto-focus the first link in my popup.html ? I know I could probably do some roundabout hack with JS or change the :focus CSS, but I think this is throwing off something else I'm trying to do and I'd prefer to stop the root cause of it. 回答1: The easiest (and javascript free!) way is to simply add tabindex="-1" to any element which you don't want to receive automatic focus. 回答2: Perhaps auto-focus was intended for a convenience, but