JavaScript Code Snippets


07 September, 2019   

Normally the tab key moves to the next focusable thing. This inserts a tab character in instead.

When a KeyboardEvent fires, you can test which key was pressed because that event contains information you can write logic against.

13 May, 2019   

It makes things draggable and with a specified handle optionally

17 February, 2019   

Missing images will either just display nothing, or display a [ ? ] style box when their source cannot be found. Instead, you may want to replace that with a "missing image" graphic that you are sure exists so there is better visual feedback that something is wrong. Or, you might want to hide it entirely. This is possible because...

28 January, 2019   

Usually, when one event loads, it writes over any previous ones. Using this snippet, you can add several events to one page without any problems.

26 November, 2018   

Cross-browser method for testing for pop-up blockers.

23 May, 2018   

Add to bookmarks bar, select text, click it to get the word count.

Find the length of the array before using it in the for function

JavaScript code snippet to Remove the Last Character from a String

Javascript append function "DOM Append Text and Element Functions"

The Gmail Bookmarklet will add a unique string to the email signature to prevent Gmail from trimming the content.

29 December, 2016   

JavaScript code snippet to test if Mac or PC

21 December, 2016   

Convert Polygon to Path Data code snippet by Chris Coyier

A JavaScript implementation of the famous sprintf() function

11 September, 2016   

Website won't display in a frameset. Site will jump out of the frameset.

24 July, 2016   

Dynamically add form fields to your forms.

28 June, 2016   

JavaScript code example for Parse Zapier apps list

Use this in the <head> of your HTML files.

13 December, 2015   

Bind onload function to the iFrame and set the size of the iFrame to the iFrames loaded content. In the example jQuery is used.

18 November, 2015   

Bind onload function to the iFrame and set the size of the iFrame to the iFrames loaded content. In the example jQuery is used.