Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

User annotations in Ajax

Let users add sticky notes to your Web site

Greg Travis (mito@panix.com), VP, Technology Development, Dynamic Logic
Greg Travis is a developer and technology writer living in New York City. He spent three years in the world of high-end PC games before becoming a consultant. He specializes in a variety of Web technologies, including real-time graphics and sound, and is the author of JDK 1.4 Tutorial (Manning Publications, 2002).

Summary:  The ability to add notes and comments to your Web site can be a powerful and attractive feature for users. This tutorial demonstrates how to implement an Asynchronous JavaScript and XML (AJAX)-based user annotation system in the form of yellow sticky notes that sit on top of regular Web page content.

Date:  17 Oct 2006 (Published 31 Jan 2006)
Level:  Intermediate PDF:  A4 and Letter (159 KB | 28 pages)Get Adobe® Reader®

Activity:  12013 views
Comments:  

Before you start

Learn what to expect from this tutorial, and how to get the most out of it.

About this tutorial

With the AJAX techniques in this tutorial, you will give users the power to add stickies to your Web site. Users can add these stickies to any Web page with a bookmarklet created just for your site. You don't have to use any particular technology generating your site, and you don't have to change your existing pages. The only additional, required configuration is a back-end Perl script that stores the annotations.

AJAX techniques can be complex and involve a combination of HTML, JavaScript code, and server-side code -- in other words, every kind of basic Web technology. This tutorial touches on the role of each of these technologies and demonstrates techniques that make this kind of programming easy and reliable.

You'll cover the steps to set up the Stickies system. You'll also gain insight into AJAX's structure and how it integrates with traditional Web page technology.


Objectives

In this tutorial, you learn how to create a Stickies application in the JavaScript programming language, including how to create a bookmarklet that invokes the system and install a back end to store the data.

In particular, this tutorial covers the following topics:

  • Create and load the stand-alone JavaScript code for the Stickies system
  • Run the JavaScript code from a bookmarklet
  • Bootstrap the code for the Stickies system
  • Create the Stickies code
  • Interact with the Document Object Model (DOM) for your Web pages
  • Make stickies that can be edited
  • Create a class that allows stickies to interact with your server
  • Save and load stickies data

The best way to use this tutorial is to read through it, and then download and install the source code (see Download). You can modify the source to try new things, or use parts of it in your own programs.


Prerequisites

To use this tutorial, you should have a basic familiarity with JavaScript code and DOM. Although the end is written in Perl, its implementation isn't the focus of the tutorial, so knowledge of Perl isn't required.


System requirements

You'll need the following:

  • A Web server that can run any kind of Web site, and that can run a simple Common Gateway Interface (CGI) script written in Perl. This server can be the same one as the content Web server, or a different server entirely.
  • The stickies require JavaScript to run. JavaScript is, as always, a moving target, so I cannot guarantee that the code in this tutorial will run in any browser. That said, I know the code works in recent versions Firefox and Mozilla.
  • The source code for the Stickies system, which is in the stickies-src.zip file under Download.

Configuring Firefox to use the sample code

Firefox by default will not allow cross-domain XMLHttp requests. To get the sample code to work with the Firefox (Windows) client and the Apache (Linux) server, you need to:

  1. Change a setting in about:config from false to true:
    signed.applets.codebase_principal_support

  2. In your JavaScript code, request the right to bypass security. Add this code to the top of the xmlRequest function:
    try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
    } catch (e) {
    alert("Permission UniversalBrowserRead denied.");
    }
    

  3. Finally, of course, set up Apache to allow the execution of the persistence.cgi script. (See Resources for information about the ExecCGI options flag in the Apache documentation and on how to use about:config to configure Firefox to use the Stickies software.)

Acknowledgement: Thanks to reader Lars Kermode who provided the above information on using Stickies software in Firefox.

1 of 15 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Web development, Java technology, Open source, XML
ArticleID=486334
TutorialTitle=User annotations in Ajax
publish-date=10172006
author1-email=mito@panix.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.