Bookmark Javascript

The javascript option for bookmarks is intended as an extension to bookmarks which allows for additional functionality than what is provided by the substitution tags. In other words, if something cannot be accomplished through substitution tags, then consider using javascript. This discussion assumes you are already familiar with writing javascript code.


Each bookmark is associated with at most one URL and one javascript function. Both components of a bookmark are optional.

NO

Substitute tags in URL

Load URL

javascript?
Stop
Substitute tags in javascript

Execute javascript

Return value?

NO

Stop

Load URL

URL?
Is it a URL?

NO

YES

YES

YES

YES

NO

Start
Stop

Display value

The javascript component is executed by the browser after it has finished loading the URL and has access to any elements already loaded in the browser using the standard javascript DOM elements.


If no URL is provided as part of the bookmark, then the previously loaded html will be accessible to the javascript. This is how to create  a bookmark which acts on an already loaded web page.

Bookmark Execution Flow

Accessing HTML Elements

Examples:

document.getElementById("myElement")

doument.body.innerHTML


Access an element named ‘myElement’.

Access html body as a string.

Waypoint information can be made available to the javascript by adding assignment statements.

Accessing Waypoint Properties

Example:

var code = ‘[WAYPOINT]’;


Assigns the waypoint code to the variable ‘code’.

The return value is the result of the last javascript statement. Do not put ‘return’ in front of it.

Return Values

Examples:

“http://coord.info/[WAYPOINT]”;


var x=”www.GBHomeTech.com”;

“http://” + x;


Has the same result as URL: http://coord.info/[WAYPOINT]



Combines a constant and a variable resulting in: http://www.GBHomeTech.com

If you would like to use square brackets ‘[ ]’ or curly braces ‘{ }’ in the javascript and do not want them confused for user-defined substitution tags, then either:

  1. Ensure the first character after the ‘[‘ or ‘{‘ and the character just before the ‘]’ or ‘}’  is a space, tab, or return.

  2. Ensure there are two or fewer characters between the brackets (ex. ‘[i]’).

Note