(This question is similar to this one, but it’s for using XMLHttpRequest instead of an iframe for Comet.) I’m starting an async long poll like this: If I do this inside <script>…</script> in the head, it will cause the document to keep loading forever. (I’m testing this in Safari on Mac OS X and the iPhone, and it’s the only
Tag: javascript
Check if a string has white space
I’m trying to check if a string has white space. I found this function but it doesn’t seem to be working: By the way, I added quotes to RegExp. Is there something wrong? Is there anything better that I can use? Hopefully JQuery. Answer You can simply use the indexOf method on the input string: Or you can use the
how to detect when a shortcut key is pressed in javascript
How can i detect a shortcut key, [ in my case [ ctrl + shift + k ] ] in javascript? Like, i have to show a dialog if user presses this key. Answer Ontop of the url Dominic posted will give you the key codes.
How to avoid scientific notation for large numbers in JavaScript?
JavaScript converts integers with more than 21 digits to scientific notation when used in a string context. I’m printing an integer as part of a URL. How can I prevent the conversion from happening? Answer There’s Number.toFixed, but it uses scientific notation if the number is >= 1e21 and has a maximum precision of 20. Other than that, you can
Ctrl + Enter using jQuery in a TEXTAREA
How do I trigger something when the cursor is within TEXTAREA and Ctrl+Enter is pressed? I am using jQuery. Answer You can use the event.ctrlKey flag to see if the Ctrl key is pressed. Something like this: Check the above snippet here.
How to get a DOM Element from a jQuery selector?
I’m having an impossibly hard time finding out to get the actual DOMElement from a jQuery selector. Sample Code: and in another piece of code I’m trying to determine the checked value of the checkbox. And please, I do not want to do: That gets me around the checkbox, but other times I’ve needed the real DOMElement. Answer You can
fastest MD5 Implementation in JavaScript
There are many MD5 JavaScript implementations out there. Does anybody know which one is the most advanced, most bugfixed and fastest? I need it for this tool. Answer I’ve heard Joseph’s Myers implementation is quite fast. Additionally, he has a lengthy article on Javascript optimization describing what he learned while writing his implementation. It’s a good read for anyone interested
What is the ‘new’ keyword in JavaScript?
The new keyword in JavaScript can be quite confusing when it is first encountered, as people tend to think that JavaScript is not an object-oriented programming language. What is it? What problems does it solve? When is it appropriate and when not? Answer It does 5 things: It creates a new object. The type of this object is simply object.
e.which ENTER key enabled only if input field focus
I am using a e.which of jquery for running a function on press of ENTER, but I want this function to be called only if the particular input field is focused (where the cursor is blinking). My current jquery function. I want that $(“#search”).click(); to be called only if the #search_text is focused or has some input, because I have
Fetching rendered JavaScript from a page (Omniture pixel)?
I have some code (incidentally, it is for Omniture SiteCatalyst) that renders a 1×1 pixel based on some JavaScript object variables I set in the page’s source code. The JavaScript eventually creates an img based on the scripting code, but the img src isn’t hard-coded into the HTML. How can I figure out what the img src is, given the