JQuery :: KeyDown Event - Clear Memory From Pressed Keys
Aug 17, 2011
I have a code for the keydown event:
-when you press the UpArrow key the image moves up
-when you press the DownArrow key the image moves down.....and so on
But don't forget that this is under the keydown event...so when I keep pressing the UpArrow key the image moves up but when I release the key the image still moves up. I already put the code $('myImage').stop(); on my image on keyup event but this doesn't do anything. There is a code to clear my memory from pressed keys or something?
I am using javascript to load and parse a big xml file (around 1 mb) save some values to an array and draw a picture using google Flot. Unfortunately, this causes the browser to crash! Is there a way to clear the memory of the browser?
I'm trying to get a keydown function to trigger an event... The same as the onclick event I currently have working. I got the buttons to work on keydown, but I cant get them to work just like the onclick. Trying to get them to do the same thing.
So I have an event handler for the KeyDown event in a Javascript file but for some reason it does not get called the first time a key is pressed. However, if a key is pressed or a mouse button clicked then the next time I press a key it does get called. Here is the relevant code:
........................... // Other stuff $(function()
When I upgraded to jQuery 1.7.1 (from 1.5.x), I found that an exception was suddenly thrown on every keydown event on an INPUT type="text". I still get the exception when I remove my change and keyup events. Previously I bound to these elements with .live, but I have the same issue with the new .on, so I don't think this problem is even related to my bindings.
The exception is as follows (from the custom WebKit frame where my script runs):
This occurs on line 3255 of jquery-dev-1.7.1.js, which reads:
I did some poking around and found that handleObj.origType is "keydown". There is no jQuery.event.special["keydown"] defined, meaning that the first part of the expression evaluates to undefined (there is no such thing as {}.handle). The second part of the expression, handleObj.handler, evaluates to true. The entire expression therefore evaluates to true, which can't be applied as a function.
I am trying to use the jquery keydown event.I wan to fade in a div that is a form then when the user presses keycode 17 meaning control key this div and form will fade in at the center of the screen.here is the code I have:
This is in a php file and echoing the code. So the " " ignore it it's just saying to php that those are to be echoed as " " This code isn't working. I would press control key but no fade in occurs. I include this php file to all my websites webpages which are php files.
I have a parent element that registered to the keydown event.somewhere down the hierarchy I have a table and some buttons. It appears that after I press the buttons, I only get the keydown event in the parent after 3 key strokes.I put breakpoints and the event is simply not called.I'm guessing this is a focus issue, but couldn't make it work.
I am trying to handle keystrokes on a text input element, in the keydown event. I need to know what character is about to be inserted into the string. I am able to get it for almost all letters, numbers and symbols using a combination of event.shiftKey, event.charCode, and String.fromCharCode() and some hard-coded lookup tables. (i'm aware that this is probably not going to work on non-standard/non-american keyboard layouts)
Unfortunately I can't get the character for a few: question mark, angle brackets, underbar, colon, and a few others. They all have charCode of zero, and nothing else in the event indicates which is which. Other than waiting till the element's value has changed (i.e. the keyup or keypress event), what can I do to tell which key is pressed?
I want to use an onkeydown() on my web site and the web site to know which key I pressed. Specifically know I pressed the arrow keys and store which key was pressed in a variable.
I have a question regarding how to prevent memory leaks in Internet Explorer when using closures. I already knew about the circular reference problem, and until now was able to prevent memory leak problems. But I needed to store DOM elements and can't solve it anymore. So I search the group archive to see if I missed any valuable information. I found some interesting articles, but somehow could not apply it to my problem or I did not understand it fully. In particular the articles that talked about setting variables to NULL seemed as an easy solution, but I think I didn't understand it, because it didn't seem to work.
So, let me explain my problem in more detail. I am working on some very dynamic and complex page. It uses AJAX (XMLHttpRequest) to alter different parts of the page. This already disqualifies the finalize method solution to cleanup memory leak problems. I use several "component classes" to do the work of creating DOM elements in some container element and provide an easy to use interface for manipulation the content. For example I can call component.setBackgroundColor("red") and the component takes care of changing the style on the correct DOM element that is encapsulated in the component. In reality the component uses more complex interface method, but I hope you get the picture of why I do this.
Let me show you some example code:
function MyComponent() { var div; var handler = null;
this.generate = function generate() { div = document.createElement("div"); div.onclick = MyComponent.createClickHandler(this); // normally more elements are created here return div; }
this.setBackgroundColor = function setBackgroundColor(value) { div.style.backgroundColor = value; }
this.getHandler = function getHandler() { return handler; }
this.setHandler = function setHandler(value) { handler = value; }
}
MyComponent.createClickHandler = function createClickHandler(component) { return function(event) { var handler = component.getHandler(); if (handler != null) handler(event); } }
This "component class" can be used like this:
var container = document.getElementById("container"); var component = new MyComponent(); container.appendChild(component.generate()); .... component.setBackgroundColor("red"); component.setHandler(function(event) {alert("Stop touching me!")});
The problem, of course, is that this code will create a memory leak in Internet Explorer. I need the component in the event handler to get the handler dynamically, but the div is stored there too, creating a circular reference.
One of the things I tried doing is making a DOMStorage "class" like this:
function DOMStorage() { var map = new Object();
this.get = function get(id) { return map[id]; }
this.put = function put(id, obj) { map[id] = obj; }
}
var storage = new DOMStorage(); //global
Instead of storing the div element directly in the component, I store it under an id in the DOMStorage and use it to retrieve it later. This actually prevented the memory leak. I don't really understand why, because I still see a circular reference. Maybe Internet Explorer does not count references in the global scope as a circular reference? When I move the global storage to inside the container object I get the memory leak again.
Unfortunately I am unable to use a global DOMStorage, because the "component class" in instantiated many times, and they must all have their seperate DOM elements.
Perhaps I have to generate unique ID's when I put a DOM element into the global storage? It seems so over-the-top for something that works perfectly fine in Firefox.
I have a <select> object that i've set up an onchange event that fires in IE fine when I use the cursor up and down in the list, but If I use the cursor up and down in Firefox the event doesn't seem to fire until I've left the field....If i use the mouse all is fine, only when using the cursor keys does it not fire the onchange event in FF.
I am making a php/mysql epos system for my shop which will be run from a browser on my shop PC. I have large buttons which I would like to be able to 'click' by pressing something like the F-buttons at the top of the keyboard. Is it possible to override the standard button shortcuts for a web page. This is only going to be on my shop computer so accessibility is not a problem.
I've got a checkbox that, when clicked, displays new text inputs. However, when I "uncheck" the box, the fields don't disappear unless I reload the entire page. What code can I add to reset the box to null when it is unchecked?
Here's the function code I have:
<script> function showUserReg() { document.getElementById("userReg").style.display = "inline"; }
What I'm trying to do is display a menu on keydown, having it go away when the key is pressed again. Specifically I'm using the "M" key. Here's my code so far:
[Code]...
The highlighted section is what I want. I already know that this won't work, because I've tried it then re-read the description and realized that ".toggle" binds to the click function. That's fine, but I need the same functionality on a ".keydown" event.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title></title> <script type="text/javascript"> function TextScroll(scrollname, div_name, up_name, down_name, top_name){ [Code]...
When I use mouse wheel in Firefox to scroll contents of the DIV, memory usage in Firefox goes through the roof. Code above is a fully working page, if anyone would like to see what's up, just load it up, and start moving your mouse wheel in the area with text. You don't actually have to scroll the text, just moving the wheel back and forth in that DIV will do. Memory usage will start going up quite fast, and after you stop moving the wheel, it will finally come down a bit after a short while. I've highlighted in red the line where mousewheel event is registered for Firefox. I'm not sure if it's really a problem, but since Opera and IE don't have any strange memory usage, and Firefox does, maybe I did something wrong. In everyday use it shouldn't matter [don't expect to have kilometers of content to scroll], but anyway, it is a bit unsettling.
Could anyone shed some light on why this might not be working? Nothing happens when I press either the left or right key... Well, I have put an alert screen in there that does work - the problem is that I want the a#previous_link to be followed, but nothing happens!
I currently have 3 jQuery events assigned to the document keydown, keyup and click.
Here is my code:
var logkeydown = false; $(function(){ $(document).keydown(function(e){ var key; e?key=e.keyCode:key=event.keyCode;
[Code].....
They toggle the boolean value of whether the keyboard key 'e' is currently pressed. If so, when the user clicks any of the site, I have a Thickbox fading in. This works great in Firefox and Safari, but IE7 begins to fade in the Thickbox (btw, I slightly altered the thickbox code to fade it in/out) but halts half-fade until the 'e' key is released.
I have a slight problem in FF3.5 that unbind('keydown'); is not working properly.. $("#q").unbind('keydown'); $("#q").keydown(function(e){ var code = (e.keyCode ? e.keyCode : e.which); if(code==40 || code==38) { var totalResults=$("#quick-search-results li"); var selectedResults=$("#quick-search-results li.qs-selected"); if(code==40) { var nodeIndex=($("#quick-search-results li.qs-selected").length<=0) ? 0 : $("#quick-search-results").index('li.qs-selected'); alert(nodeIndex); }}}); // end keydown
The above code alerts once on first keydown (with the down arrow key [code==40]), twice on the second, three times on the third and so on.. it worked fine in FF3 but a recent upgrade to FF3.5 seems to have broken the functionality..
The event which in the following keydown function code is not returning the correct key codes. I have checked this in Chrome using the developer tools and the console.log(e.which) statement in my code.
Im trying to add a class to an element when the down arrow is pressed using keydown but once you release the down arrow the class is removed from the element.Is this normal behaviour?
I have a search form and added the "Clear All" Button functionality...but it clears the last part of the search form display preferences....how do I only clear the checkboxes at the top of the form only and not at the bottom of the form between the <DIV> tags? I have attached a copy of the JSP page.
I'm trying to get some elements enabled when a user start typing in a input field but without success. I try this codes:
$('#keyword').focus(function() { alert('Handler for .focus() called.'); }); $('#keyword').keypress(function() {
[Code]....
But none of them works. Just try in this page [URL] and start typing in "Buscar" (spanish) or "Search" (if you change to English) input and see that nothing happen and I don't know why. Note that I wrote alert() just for see if it works or not.