SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Extending the Browser : Your First Extension

All extensions are made avaiable on the browser's context menu. The context menu is displayed whenever the user right clicks on a document. We will demonstrate a quick extension that displays your document's URL. In the example, we manually register the component so you can see exactly how the extensions work.

  1. First, create a new HTML document with the following script:
      <SCRIPT>
        var win = external.menuArguments
        alert("URL: " + win.location)
      </SCRIPT>
  2. Save this document as "url.htm"
  3. Run Regedit. RegEdit allows you to edit your registry. Be careful when using RegEdit as editing the wrong values can cause problems running windows or other programs.
  4. Navigate to the following key (keys are the labels inside of the tree list):
      HKEY_CURRENT_USER
        Software
          Microsoft
            Internet Explorer
    
  5. You should see a key inside of Internet Explorer called MenuExt. If no such key exists, add a new key from the Edit, New, Key menu option. Give the key the name "MenuExt"
  6. Expand MenuExt
  7. Add a new key with the name "&URL...". This string will be displayed in the context menu of the browser.
  8. After adding this key, double click on the "default" value (or right click and choose modify). The value for this key should be a URL to the url.htm file saved above. Therefore, for file paths, be sure to start with the "file://" prefix (eg., file://d:\url.htm)
  9. Quit regedit and all instances of Internet Explorer
  10. Run Internet Explorer and navigate to a web page
  11. Right click on the page and choose URL. You should now see the URL for the current page.

You now have created your first extension. To remove the extension, run RegEdit and delete the key representing the menu choice (you do not have to delete the MenuExt key).

When you pasted the URL script, you may have noticed the use of the external object. The external object is used in Dynamic HTML to reference properties that are from another context. In this case, the menuArugments property is used to access the window instance of the browser that called the extension. If you are familiar with scriptlets, the external object should not be new to you as its used to raise events in the containing application.

Since the menuArguments property represents a window object, you can use it to navigate from the window to the displayed document. Next, we take you through building a more complete and useful annotate extension.