Question

The documentation states that "Safari 5.1 sends an "activate" event to a window or tab whenever it is activated". I use the following code in my global page to capture this event:

function onWindowOrTabSwitched(event) {
     alert("onWindowOrTabSwitched");
}

safari.application.addEventListener("activate", onWindowOrTabSwitched, true);

The alert shows when I switch from one tab to the other, but when switching between Safari windows, most of the time, nothing happens. Is there something I'm doing wrong or doesn't Safari (6.0.2) not dispatching this event on switching between windows?

Was it helpful?

Solution

Okay, the real problem seemed to be that the message I send during the "activate" event from my global page to the injected script does arrive when I create a new Safari windows, but doesn't on any other situation. "safari.application.activeBrowserWindow.activeTab.page" seems to be filled during the activate event while creating a new window, but is cleared as soon as the topsites:// page is loaded. I implemented a check in the injected script to see if it's injected in a http(s) page or to resolve this problem.

So the activate event does fire everytime it should fire, only sending messages to a Topsite is only possible in the case that a new window is just opened and that was my problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top