JavaScript

Posts about the client side scripting language JavaScript.

Randomise JavaScript Array

Friday, July 4, 2008 - 09:43

Randomising a JavaScript array can be done in one or two ways. The easy way is to create a function that returns a random number and then use the sort() function of the Array object to sort the array by a random value.

Category: 

Merge Two JavaScript Arrays

Thursday, July 3, 2008 - 09:09

Here is a simple bit of code that you can use to merge one or more arrays. The function you need is called contact().

Take the following two arrays, both of which contain numbers.

Category: 

Loading Page Styles And JavaScript With JavaScript

Wednesday, July 2, 2008 - 09:50

One good technique when using JavaScript is to load a single JavaScript file and get this file to load any other JavaScript or CSS documents that are needed. This means that you can simplify the instillation of a script on a page by including a single file, which then loads everything else it needs. Here is how to accomplish such a task.

Category: 

Enabling Tabbing In A Textarea

Friday, June 20, 2008 - 09:42

When a user presses the tab key in a browser window the normal action is for the user to move the focus to a different control. To enable a word processor like tab effect in a text area you need to catch the keystroke and add in the tab character to where ever the cursor is. This is the main issue with creating this solution, it is easy to add a tab to the end of the text, but most users might want to add a tab half way through the text.

Take the following HTML text area.

Category: 

JavaScript To Stop Frames

Tuesday, May 27, 2008 - 11:58

The following section of JavaScript will detect if anyone is viewing your page in a frame. If they are then the code will redirect them to your site. It essentially stops people using frames to poach your content and stops online proxy software from viewing your site.

Category: