Jonathan Snook.ca

 

Using getBookmark and moveToBookmark

The getBookmark method doesn't do what you might initially think. It doesn't allow you to create a link to an internet shortcut or get one from the user's machine. What it does do is it creates a "snapshot" of a selection so you can return to it later. The information returned from the getBookmark method is opaque. This means that it is unreadable and doesn't have any context on it's own. It can only be used by the moveToBookmark method to move to the saved selection.

Example:

Select any text on this page and then click here: . This has created a bookmark that has been saved to a variable. Now, select another block of text on the page and then click here: . You now have two bookmarks stored in variables that can be retreived at any time.

An example application of this feature could be a content highlighter for your companies intranet. It would allow your employees to browse articles and highlight information that they found interesting. The bookmarks to this highlighted information could be stored in a database. The next time the user browsed to the page you would use moveToBookmark to "relight" that information.

Problems with getBookmark

The biggest problem with using getBookmark is any change that is made to the HTML on the page may cause unusual behaviour. Any content within a sentence of the content that has been changed will likely cause the moveToBookmark method to either select the incorrect text or not work at all. This is especially troublesome when using these methods with the MSHTML or DEC as the likelihood of the content having changed since you bookmarked it is quite likely.

If you have some interesting uses for these methods, send them in!

MSDN Reference: getBookmark method
MSDN Reference: moveToBookmark method

March 30, 2003