HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"Putting JavaScript Bookmarks to Work"
Volume: 4 Issue: 1, p. 60


Listing 1:
javascript:window.location='http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=' +

Listing 2:

javascript:var A='http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va='; var sel =
 document.selection; if (sel) {var rng = sel.createRange(); if (rng) { if (rng.text !='') 
{ document.location=A + escape(rng.text.toLowerCase())}}}

Listing 3:

javascript:var A='http://www.altavista.digital.com/cgi-bin/query?pg=q&stq=20&what=web&kl=XX&q="';
var C='"'; 
function docsel (doc) {if (doc.getSelection() !='') { document.location=A +
 escape(doc.getSelection().toLowerCase()) + C}}; 
function use_win(w) {docsel(w.document)}; 
function test_win(w) {if (w.frames.length >= 1) {for (i=0; i<w.frames.length; i++)
 test_win(w.frames[i])}} else {use_win(window)}}; 

Listing 4:
javascript: // instead of the usual http://

// These two variables describe the CGI

// program to be used for searching.

var A='http://www.m-w.com/'

+ 'cgi-bin/dictionary?book=Dictionary&va=';

var C=''; 

// docsel() will check a document for a text

// selection and search for it if it exists.

function docsel (doc) {

// Use Netscape’s selection 

if (doc.getSelection() !='') {

document.location=A + 


+ C



// use_win() will perform our action on

// each window. Called by test_win().

function use_win(w) {



// test_win() will recursively walk through

// all frames and execute use_win() on each

// one.

function test_win(w) {

if (w.frames.length >= 1) {

for (i=0; i<w.frames.length; i++) {


test_win(w.frames[i]) // Tail recursion


} else {




// Start the recursive walk through frames


Listing 5:

javascript:var A='http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va='; 
var C=''; 
function docsel (doc) {var sel = doc.selection; 
if (sel) {var rng = sel.createRange(); 
if (rng) { if (rng.text !='') { document.location=A + escape(rng.text.toLowerCase()) +
function use_win(w) {docsel(w.document)}; 
function test_win(w) {if (w.frames.length >= 1) {for (i=0; i<w.frames.length; i++)
 {use_win(w.frames(i)); test_win(w.frames(i))}} else {use_win(window)}}; test_win(window.parent)


All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.