문제

I've seen that SafariBeforeSearchEvent event fires before the Smart Search Field performs a search. So I've started to try it out, but it isn't works or my code is wrong. Here's my code:

safari.application.addEventListener("SafariBeforeSearchEvent", handleBeforeSearch, false);

function handleBeforeSearch(event) {
    alert("Test");
}

And when I search something using the smart search field, no alert appears. Why is that?

도움이 되었습니까?

해결책

The name of the event is "beforeSearch", not "SafariBeforeSearchEvent" (which is the class of the event).

Also, if you're going to listen for this event at the application level, you may need to set the capture parameter to "true".

safari.application.addEventListener("beforeSearch", handleBeforeSearch, true);

See the documentation here.

다른 팁

Looks like in App-Extensions this API is no longer available.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top