Safari 扩展:选项卡更改事件?
我试图在 Safari 中的页面上弹出一个特定于选项卡的弹出窗口,并由按钮触发(可以明显切换)。如何确保当切换到选项卡时,按钮将正确切换,即如果弹出窗口可见则突出显示;不然的话。
我四处寻找“选项卡切换”类型的事件来监听,但这不起作用,焦点也不起作用。
有什么想法吗?
干杯。
Possible Duplicate:
Safari 5 Extension: How can I detect when a window's current tab has changed?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与 chrome 不同的是,chrome 为窗口和选项卡更改等事件提供了特殊的 API,
您仍然可以使用 Safari 扩展来完成此操作。
你只需要让你注入的 javascript 设置事件监听器
参加您想要的活动。
然后,如果扩展的全局或其他部分需要该信息,您可以使用 postMessage 命令在消息中传递该信息。
注入.js:
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: