Wednesday, 20 February 2013

Focus/Blur event propagation

So I'm making a dynamic menu work better for keyboard users and just thought it'd take 10 mins to add device independent event handlers to the existing code. Did that, hit Ctrl+F5 a couple of times and nothing happend.

It turns out, not all events propagate, which when you think about it makes sense. I'm using YUI for this particular project so need the focus event module, if your hand rolling you'll need use the IE focusin/focusout events, and for everything else register your event listeners in the capturing phase, check it out on quirksmode.org.





 

Wednesday, 6 February 2013

Chrome extensions don't run on first use

Okay, so I'm having this problem with my chrome extensions. The user downloads and installs an extension, clicks on the icon and boom, nothing happens! The reason being, page loaded before your extension was installed don't contain the content scripts.

As yet, I haven't found a work around but, at least, using the following you can send an alert to the page and tell the user whats happening...
/* in the background.js */

chrome.browserAction.onClicked.addListener(function(tab){ 
    linkAudit.log('alert if not loaded'); 
    chrome.tabs.executeScript(tab.id, {
     code:'if(!window.linkAudit){alert("Please reload the page to run Link Audit")}'
    }) 
});
Investigate the Link Audit extension.
 

Note: the opinions on this page don't represent that of my employer in anyway. And, actually only vaguely represent my opinions on the date of publication. (Unlike Ms T, I am very much for turning)