views:

73

answers:

2

I'm trying to have a popup over a page in Safari which is tab-specific, and triggered by a button (which can visibly toggled). How can I ensure that when a tab is switched to, the button will be correctly toggled, i.e. highlighted if the popup is visible; not otherwise.

I looked around for a "tab switch" kind of event to listen for but that didn't work, nor did focus.

Any ideas?

Cheers.

A: 

Unlike chrome which provides a special API for events like window and tab changes, you can still do it with safari extensions.

You simply have to have your injected javascript set up event listeners for the events that you want.

Then if that info is needed by global or other parts of the extension, you can pass the info in messages using the postMessage command.

injected.js:

window.addEventListener("load", loaded, false);

safari.self.tab.dispatchMessage("somethinghappened","load");

Galt