Addon JavaScript Code Snippets

These JavaScript scripts can be used in conjunction with other snippets to enhance their usefulness. These can save you a great deal of time. Many of these are generic and can be used in most snippets.

Add a button to allow your visitors to print your Web page. Compact and simple, yet highly requested.

This snippet is a function that validates a URL. It can easily be added to your current validation script.

Unequal column heights make CSS layouts difficult to manage when the height of content cannot be known in advance, particularly in scenarios where absolute positioning is in use. While there are a variety of strategies to deal with this issue, here’s a jQuery-based fix.

Many times you just want a popup window to stay open for a few seconds, or a bit longer. Place this snippet in the body tag of the popup window.

Use this script to ensure that a user can only reach a given page from another specified page. Easy to set-up and use.

Object detection is common in JavaScript. Browser irregularities mean that your code must sometimes contain branches for different browsers. Use this snippet to perform object detection once instead of every time you call addEvent.

Grab these regular expressions to use in your own JavaScripts. They can add another dimension to your programming experience.

You can remove existing nodes using the DOM. The removeChild method allows any node to remove one of its child nodes. Simply pass a reference to the node you wish to remove. Any text or elements within the node being removed will be removed along with it.

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.

This is a simple, cross-browser method for testing for pop-up blockers. Most scripts test the return value of and conclude that there is a blocker installed if the returned value resolves to false in a boolean statement. However, these scripts fail with browsers such as Opera (as of v9) that return a window object but disable it. This script properly handles this, as well as a null or undefined return type.

Use this snippet to detect if the client browser is using a popup blocker. If a one is detected, the script can then perform a different action. The sample uses an alert box to inform the user whether a popup blocker is present or not.