Here is a slightly updated version of the code from my previous post. The alert box that appears will also display the title and url for the current page. Try the bookmarklet on different pages and you will see it has access to the current document.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>Hello World</title>
</head>
<body>
   <a href="javascript:{alert('Hello World!\n\nFrom ' +     
      document.title + ' @ ' + document.location.href);}">
      Hello World!</a>
</body>
</html>

Advertisements