[Project_owners] Overlaying Java Script

Paul Roub paul at roub.net
Wed Mar 23 15:01:53 EST 2005

> For doing this, I have to overlay the js function called
> BookmarksMenu.loadBookmark ();, or maybe some other as well. The thing I
> don't know how I can do that. I know overlaying the .xul, however how
> can I interrupt my own js methods to such built in methods. Basically
> what I want is to make bookmark clicks to pass url to my own function so
> I can handle it. And for sure do the usual loading url thing.  

This is ugly, unfortunately -- the bookmarks menu stuff is fairly 
unfriendly to overlays.  I'm dealing with a similar issue in IE View 
test builds ( http://mozdev.org/bugs/show_bug.cgi?id=9001 ) right now.

When my overlay initializes, I stash a reference to the original 
BookmarksCommand.openOneBookmark function, then assign 
BookmarksCommand.openOneBookmark to my own function.  When a link is 
clicked, I get the event.  If it's a link that meets my launch-in-IE 
list, I take action; otherwise, I call the old handler, passing in all 
the parameters I received.  The relevant code is:

// <snip>
if (BookmarksCommand && BookmarksCommand.openOneBookmark)
     //  openOneBookmark: function (aURI, aTargetBrowser, aDS)
     gOldOpenOneBookmark = BookmarksCommand.openOneBookmark;

     BookmarksCommand.openOneBookmark = function(aURI, aTargetBrowser, 
aDS) {

         var url = BookmarksUtils.getProperty(aURI, NC_NS+"URL", aDS);

         if (IeView.forceIe(url))
             IeView.ieViewLaunch("Internet Explorer.lnk", url);
             gOldOpenOneBookmark(aURI, aTargetBrowser, aDS);
// </snip>

See the complete overlay source at 

This works, but apart from just making me feel *dirty*, it could easily 
break if the BookmarksCommand object changes.  Anyone have a better way?


More information about the Project_owners mailing list