1. Home
  2. Computing & Technology
  3. JavaScript
photo of Stephen Chapman
Stephen's JavaScript Blog

By Stephen Chapman, About.com Guide to JavaScript since 2004

You Can't Protect Your Page Content

Thursday November 12, 2009
Web pages are open source and there is nothing you can do to protect the content

Every so often I receive emails about my Image Protection JavaScript that places the image in the background of a table with a transparent image in front of it. All of these emails have pointed out that there are other ways to obtain the image and that it is not really protected. In fact there is no way to stop people obtaining the content of your web page since they have it already on their computer when they view your page. The same is true even if you use JavaScript to encrypt your page source since your visitors all have something that can decrypt it for them (called a web browser). In fact applying something as simple as a no right click script (which is the least effective way to try to protect anything) will just drive visitors away from your site. Any of these techniques may stop newbie web users from taking your code and images (and will do so at least as effectively as much longer codes and more expensive solutions found elsewhere on the web) but nothing will prevent someone who knows how the web works from obtaining whatever they want from your site.

Minimum and Maximum Distance

Wednesday November 11, 2009
How far apart are specific characters? Find out with JavaScript

Continuing with our look at validating text input fields using JavaScript, the tenth tutorial in the form validation series looks at how we can test to make sure that selected characters in the input are a certain distance apart.

Minimum and Maximum Distance

Unobtrusive Add to Favourites

Tuesday November 10, 2009
JavaScript can add to the page when a feature is supported and not add when it isn't.

Having an "Add to Favourites" link is popular with people just starting out writing web pages. Not all browsers support such a link though and some pople have written scripts that use the wrong way of testing if the browser does support it. This version of the "Add to Favourites" script not only uses the correct method of testing if the browser supports the link, it supplies the necessary code for all the browsers that do provide a way to support such a link, and just leaves an empty tag in the page where the link would have gone if the browser doesn't support it.

Unobtrusive Add to Favourites

Ignore Case and Global

Sunday November 8, 2009
Regular Expressions can ignore capitals and find all matches

The second tutorial on Regular Expressions covers how to set the expression for global processing and to ignore capitalization.

Even with this most basic use of regular expressions you will be able to do searches for either the first or all occurrences of a text string. You will also be able to decide whether the exact capitalisation you used is important for obtaining a match or whether the capitalisation should be ignored.

Ignore Case and Global

JavaScript Alert

Sunday November 8, 2009
You can do some quick debugging of simple JavaScripts using alert()

The alert built in function has little to no use in live JavaScript code (particularly since some browsers display an option to turn off JavaScript at the bottom of the alert) but it is still useful for finding and fixing errors in JavaScript code when you are testing in a browser that doesn't have a debugger built in (such as Firefox).

JavaScript Alert

Unobtrusive JavaScript

Saturday November 7, 2009
JavaScript belongs in a separate file linked from the head of your page.

There is no longer any need to clutter the body of your web page with event handlers attached to tags and scripts embedded in between content. By using a few simple coding techniques we can remove all of that from the body of the web page and place it all into a separate JavaScript file that we link into our page with a simple script tag in the head of the page.

Unobtrusive JavaScript

Feature Sensing

Friday November 6, 2009
Test if the browser supports a specific JavaScript Feature directly, do not test whether the browser was one that did or didn't support that feature ten years ago.

Right from day one JavaScript has provided a simple way to check whether the version of JavaScript currently being run supports a given object, method or function. The same (or similar code) can also be used to check if a property or variable exists. Using this way of testing if the browser supports your script your script will always work in new browsers that add that support even where the prior version didn't.

Feature Sensing

Functions and Object Constructors

Thursday November 5, 2009
JavaScript doesn't have classes but objects can inherit directly from other objects

In JavaScript object constructors are defined the same way you define a function. What distinguishes one from the other is the way it is called. By testing how it was called inside your function you can make functions that are also object constructors or can test if it is called the right way.

Functions and Object Constructors

Character Order

Wednesday November 4, 2009
Characters don't have to be adjacent to be able to validate them with JavaScript

It isn't just the characters that are next to one another in the input text that may need validating. Sometimes the order in which certain characters is important regardless of whether they are next to one another or at opposite ends of the text. The ninth form validation tutorial shows you how to test for one character must follow another in the text.

Character Order

JavaScript Split

Tuesday November 3, 2009
The name of the method to call to split a string in JavaScript is rather obvious.

JavaScript has some very powerful options for being able to split up a string of text and place the results into an array.

JavaScript Split
Read Archives
Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.