Skip to content

Tag: javascript

Remove key press delay in Javascript

I have the following problem: I’m trying to write a Javascript game, and the character is being controlled by the arrow keys. The problem is, when one keeps the key pressed, there is a short delay between firing the first keypress and the repeated keypress. Also, when one presses the “right arrow …

Incrementing a date in JavaScript

I need to increment a date value by one day in JavaScript. For example, I have a date value 2010-09-11 and I need to store the date of the next day in a JavaScript variable. How can I increment a date by a day? Answer Three options for you: 1. Using just JavaScript’s Date object (no libraries): My previ…

IE6 Covering Div

I have a Google Map on one web page where I want to disable both scrolling and zooming. I accomplish this by having an empty DIV element with absolute positioning cover the map area. Firefox/Chrome work fine, but IE6 doesn’t really care about this DIV. For some reason, it just lets me drag the map. I se…

How do I include – and ‘ in this regular expressions?

I have a this regular expression below for some input name fields. How do I include an apostrophe and a hyphen in this? Answer Hyphen is already included (twice), you can add the apostrophe by just editing it into the character class: You can rewrite it to look like this, so that there’s no need to esca…

Preloading images with JavaScript

Is the function I wrote below enough to preload images in most, if not all, browsers commonly used today? I have an array of image URLs that I loop over and call the preloadImage function for each URL. Answer Yes. This should work on all major browsers.