I'm trying to detect keystrokes using Javascript. My code (so far) works in Opera and Safari, but not in Firefox, Netscape/SeaMonkey/Mozilla, or Chrome. (I have no idea if it works in IE; IE has other problems with my code.)What I've done is attached a onkeydown listener to the body tag. (I've also tried it with onkeypress and onkeyup.) Right now all I'm trying to do is detect a key press -- any key press -- and throw an alert as a result. I've tried it two separate ways -- with straight Javascript and with MooTools, which I'm using for the rest of my project.
The code I have is as follows:
mootools version $(document.getElementsByTagName('body')[0]).addEvent('keypress', function(event) { alert('key has been pressed.'); }); regular javascript version document.getElementsByTagName('body')[0].addEventListener("keypress", function() { alert('key has been pressed.'); }, false);
Both versions work in Opera and Safari. Interestingly enough, if I attach a click listener to the body using the exact same code as above, but changing the word 'keypress' to 'click', they both work in Firefox as well. I can't figure out how to get this key listener attached.
I am writing a firefox extension and I need to execute a YQL query everytime the user changes webpage on their browser.For now, all i am concerned with is detecting if their is a webpage change.For example. User is on [URL] then switches to [URL] At this point i need to call a function.So far all i can find is an onload=function()Which is only working once when the browser opens up.
Is there a way to detect if an textarea onscroll event is working in Firefox (or Mozilla). I know that there is an onscroll event bubbling bug with current vesions of these browsers so I want to detect this problem with a test like "if (textarea.onscroll == 'undefined' || !textarea.onscroll) {}."
Code: var request = new XMLHttpRequest(); request.open("GET", "http://127.0.0.1/get/file.json?filepath=c:\xxx.xxx"); request.onreadystatechange = function() { if (request.readyState == 4) {
[Code]...
using above code, I wanna implement uploading/dowloading/parsing file with json format. however, the responseText always return null in FF. It it about to make me crazy.
This has me completely stumped. I have a multiple select form element in my HTML document that needs to be manipulated by two different sets of context-sensitive controls. One set of controls is marked up as follows:
When I load this page into Safari (on Mac OS X) and set the style of divControls1 to "display:block," I have an enabled "Add" button, a disabled "Edit" button, and a disabled "Delete" button, just as I expected. (I monitor selections in a multiple selection element to turn the buttons on and off.) But when I load this page into Firefox (also Mac OS X), all three buttons are disabled at startup. My page runs a function called startup() when the body fires onLoad. To try to troubleshoot the problem, I wrote this line at the beginning of the startup() function:
function startup() { alert (document.getElementById("btnAdd").disabled); ...
When I run this code in Safari, the alert returns "false" (not disabled), just as I would expect, and intended. However, the same code in Firefox (Mac OS X) returns "true" (disabled) ... but the same code in Firefox (WinXP) returns "false"!
with jquery, i try to get the margin-left ($('#mydiv').css('margin-left'), but the function return 0px, unable to retrieve the good value (auto) anyone has idea to retrieve the value "auto" when margin-left is "auto" ?
I'm trying to use JS to move the cursor from my user login text field to the password text field - I've put the onKeyPress() event in the user input tag but then I press the Tab key the cursor doesn't move -
function detect_tab_key() { var key_code = window.event.keyCode; if (key_code == 9) { document.forms[0].frm_password.focus(); document.forms[0].frm_password.select(); } }
I would to change the color of some td cells if there is text in it. Right now this code does the job, but it changes the color of evry table. I'd like to know a way to do this on one table in my page and not all of them.
var count='0'; var TDs=document.getElementsByTagName('td') var length=TDs.length; i='0';
Why is it that you need the return keyword? Where does the argument event come from?
I know it works, I just want to know why it works.
I've been looking at some refferences and can't seem to find an answer if someone could give me an explanation or point me to a website, that would be great.
I am trying to do something I thought would be simple in javascript, and I'm at a loss. First code is GOOD code, except that it does not account for the possibility that the button(s) in question do NOT exist. The second and third subsets are two of several attempts to do just that. Code:
I need to write a script that detects if a person has flash installed and if they do then do something, if not do something else.
I can do this no problem with javascript - except for the detecting flash part. I have no idea how to have a js detect flash - or even if its possible.
If I detect an empty textbox, I fill it with a value ('Dad'). If I do this twice, the second time around IE 6 fails to notice that I've cleared the textbox again, thus leaving the textbox cleared. Is there a recommended workaround? Opera 7.23 is detecting the second deletion fine.
I am trying to detect whether a user entered text in a textarea or hit the delete/backspace button (thus, erasing something). Once that is detected, I would like to set "var bSaveRequired = true;". It would be great if this function worked cross-browser -- IE 6.0 and Firefox.
Say I'm on the site www.xyz.com and on a certain page if the user leaves the domain xyz.com, I have a popup cme up w/ stuff. I don't need to know what the new domain is, I just want to know if the user left / is leaving xyz.com.
I'm trying to determine if the user clicks the stop button during a post send, basically. Specifically, if a user is uploading a file to my server, and they click stop at some point, I need to be able to tell the server that stop was clicked, so it doesn't think that's the whole file. I've noticed that an error message is written to the Apache log, but that seems like a strange way to keep track of user-interrupted events. (Note: this is Apache/mod_perl server-side)
I guess what I'm thinking now is that JavaScript detects the stop (since it is client-side), then sends a message to the server that an error occurred, or something. Like I said, the onstop event is not doing what I'm expecting, and Firefox doesn't like it anyway, not to metion the other browsers out there. So my question is what's the "idiom" or "standard way" of detecting this sort of situation. I'm quite certain I'm not the first one to need it.