{"id":401,"date":"2007-10-29T20:37:26","date_gmt":"2007-10-30T02:37:26","guid":{"rendered":"http:\/\/blog.codedread.com\/archives\/2007\/10\/29\/firefox-extensions-and-detecting-a-clicked-link\/"},"modified":"2007-10-29T20:37:26","modified_gmt":"2007-10-30T02:37:26","slug":"firefox-extensions-and-detecting-a-clicked-link","status":"publish","type":"post","link":"https:\/\/www.codedread.com\/blog\/archives\/2007\/10\/29\/firefox-extensions-and-detecting-a-clicked-link\/","title":{"rendered":"Firefox Extensions and Detecting A Clicked Link"},"content":{"rendered":"<p>I'm working on my <a href=\"http:\/\/www.codedread.com\/fxpointer\">first Firefox extension<\/a> - an attempt to get Firefox to support some version of <a href=\"http:\/\/www.w3.org\/TR\/xptr-framework\/\">XPointer<\/a> that will work on HTML documents.  <!--more--><\/p>\n<div class=\"ads\"><object type=\"text\/html\" width=\"468\" height=\"60\" data=\"http:\/\/www.codedread.com\/gads.php\"><\/object><\/div>\n<p>If you haven't read about <a href=\"http:\/\/www.w3.org\/TR\/xptr-framework\/\">XPointer<\/a> before, you can start at my recent blog post <a href=\"http:\/\/blog.codedread.com\/archives\/2007\/10\/10\/more-on-xpointer\/\">here<\/a>.<\/p>\n<p>At the moment, things are pretty much in a raw, not-at-all-ready-for-prime-time state, though I've traveled down some lanes that I've always wanted to try out (specifically I've got my first real taste of <a href=\"http:\/\/www.mozilla.org\/projects\/xul\/\">XUL<\/a> and <a href=\"http:\/\/developer.mozilla.org\/en\/docs\/XBL:XBL_1.0_Reference\">XBL<\/a>).  Unfortunately it took me a while to get even a little clue on some of this stuff and it can be a bit discouraging.  Here's hoping the Mozilla documentation improves both in coverage and recency - but I'm not holding my breath.<\/p>\n<p>The goal is:  I want to modify the view of an HTML document if any XPointer parts show up in the URL bar.<\/p>\n<p>I started with simply adding a \"load\" event handler to the gBrowser.  This worked fine any time a page had to load (including in a new tab or in the existing tab).  However, what I noticed was that a \"load\" event would not fire if the link was in the same page (i.e. just the \"hash\" part of the URL had changed) if you clicked a link or when you typed it in.  So if I'm at page foo.html and that page has a link to foo.html#element(bar), when I click that link I do not get a \"load\" event.<\/p>\n<p>So that led me into learning a bit more about XBL to try and add some bindings to the chrome.<\/p>\n<p>Where I sit now:  I've got XBL defining an evalXPointer() method on the \"urlbar\" XUL widget.  When a new document is loaded, I invoke this method.  Also, when a new URL is entered into the location bar (and the user presses Enter), I invoke this method.  Finally, if the \"Go\" button is clicked I also invoke this method.  All my \"logic\" sits in JavaScript in the XBL at the moment.<\/p>\n<p>Anyway, I kind of get the idea that what I'm doing is not appropriate.  That's what community feedback is all about.  The above bindings seem kind of like a hack.  What I really want to do is get notified when any link has been activated (by click or otherwise) and regardless of whether this link causes a \"load\" event or if it's in the same page.  Does anybody know the sane way to do this?<\/p>\n<p>Better yet, is there a way to detect when a browser tab's address has changed in a definitive way?  I don't want to look at every keypress.<\/p>\n<div class=\"ads\"><object type=\"text\/html\" width=\"468\" height=\"60\" data=\"http:\/\/www.codedread.com\/gads.php\"><\/object><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m working on my first Firefox extension &#8211; an attempt to get Firefox to support some version of XPointer that will work on HTML documents.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,8,25,11,28,30],"tags":[],"class_list":["post-401","post","type-post","status-publish","format-standard","hentry","category-firefox","category-questions","category-software","category-technology","category-web","category-xml"],"_links":{"self":[{"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/posts\/401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/comments?post=401"}],"version-history":[{"count":0,"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/posts\/401\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/media?parent=401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/categories?post=401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codedread.com\/blog\/wp-json\/wp\/v2\/tags?post=401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}