Safari 扩展中的弹出窗口

发布于 2024-10-16 15:52:56 字数 228 浏览 6 评论 0原文

我正在尝试构建我的第一个 Safari 扩展,但我对一些基本概念感到困惑。

第一个障碍是从工具栏按钮打开弹出窗口,就像 Ebay Safari 扩展一样。

http://anywhere.ebay.com/browser/safari/welcome/

Im trying to build my first safari extension and Im at a loss on a few basic concepts.

The first hurdle is making a popup window open from a toolbar button, just like the Ebay Safari extension.

http://anywhere.ebay.com/browser/safari/welcome/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浪荡不羁 2024-10-23 15:52:57

阅读此内容: http://net .tutsplus.com/tutorials/other/how-to-create-a-safari-extension-from-scratch/

它描述了按下工具栏按钮时如何发生某些事情,您只需将其放在中间即可其中:

<script>  
// Set up the Listener  
safari.application.addEventListener("command", performCommand, false);  

// Function to perform when event is received  
function performCommand(event) {  
    // Make sure event comes from the button  
    if (event.command == "open-nettuts") {  


    **YOUR FUNCTION**


    }  
}  
</script> 

Read this: http://net.tutsplus.com/tutorials/other/how-to-create-a-safari-extension-from-scratch/

It describes how to have something happen when a toolbar button is pressed, you would just put it the middle of this:

<script>  
// Set up the Listener  
safari.application.addEventListener("command", performCommand, false);  

// Function to perform when event is received  
function performCommand(event) {  
    // Make sure event comes from the button  
    if (event.command == "open-nettuts") {  


    **YOUR FUNCTION**


    }  
}  
</script> 
旧情别恋 2024-10-23 15:52:57

据我所知,Safari 不允许我们像 Chrome 那样创建“弹出窗口”。对于我的 Safari 扩展,我使用 jQueryUI 创建弹出窗口。您还可以使用 YUI 或 Mootools。在拆解 eBay 和 Twitter 扩展时,我发现他们正在使用 iframe。我不知道他们是如何实现它的,因为 jquery 不允许你修改 iframe 的内容(如果我错了,请纠正我)。

但为了回答您的问题,您的按钮将向注入的脚本发送一个事件。该脚本可以具有与此类似的代码:

$('body').append('<div id="mypopup">');

var myPopup = $('#mypopup').dialog({
    'autoOpen' : false ,
    'draggable' : false,
    'modal' : false,
    'resizable' : false,
    'title' : 'My Popup'
});

function messageHandler(msgEvent) {
    var messageName = msgEvent.name;
    var messageData = msgEvent.message;
    if (messageName === 'buttonPushed') {
        if (myPopup.dialog('isOpen')) {
            myPopup.dialog('close');
            return;
        }

        $('#mypopup').children().empty();   // Clear out any crap should it exist
        $('#mypopup').append(someHTML);
            myPopup.dialog('open');
            return; 
        }
    }
}

这是一个非常基本的示例。我的里面有一个工具栏和许多其他东西。另外,您必须拥有非常具体的 CSS 规则,以保护您的弹出窗口的 CSS 不被世界上每个网站破坏。

我也考虑过使用 global.html 打开“弹出”窗口,但据我所知,它所能做的就是打开一个窗口。我没有看到任何用于设置尺寸等属性的工具。如果有的话,我会走这条路,因为你的弹出窗口将受到 CSS 的保护,因为它位于自己的窗口中。

As far as I know, Safari does not allow us to create a "popup" the way Chrome does. For my Safari extension I am using jQueryUI to create my popup. You can also use YUI or Mootools. In taking apart the eBay and Twitter extensions I see they're using an iframe. Just how they're implementing it I don't know since jquery doesn't allow you to modify the contents of an iframe (correct me if I'm wrong here).

But to answer your question, your button will send an event to an injected script. That script can have code similar to this:

$('body').append('<div id="mypopup">');

var myPopup = $('#mypopup').dialog({
    'autoOpen' : false ,
    'draggable' : false,
    'modal' : false,
    'resizable' : false,
    'title' : 'My Popup'
});

function messageHandler(msgEvent) {
    var messageName = msgEvent.name;
    var messageData = msgEvent.message;
    if (messageName === 'buttonPushed') {
        if (myPopup.dialog('isOpen')) {
            myPopup.dialog('close');
            return;
        }

        $('#mypopup').children().empty();   // Clear out any crap should it exist
        $('#mypopup').append(someHTML);
            myPopup.dialog('open');
            return; 
        }
    }
}

This is a very basic example. In mine there is a toolbar, and a host of other things. Plus you have to have REALLY specific CSS rules to protect your popup's CSS from being clobbered by every site in the world.

I have also thought about using global.html to open the "popup" window but as far as I can tell, all it can do is open a window. I don't see any facilities for setting attributes like size, etc. If there are, I'd go that route since your popup would then be protected from CSS as it's in its own window.

沐歌 2024-10-23 15:52:57

我认为在 Safari 下它被称为弹出窗口,这就是你的意思吗?

我注意到两件事:

  1. 如果没有命令集(在工具栏项上),则单击工具栏按钮时会自动显示弹出窗口
  2. 如果有命令集,则用户需要单击并按住工具栏按钮 直到弹出窗口显示。

I think under Safari its called a popover, thats what you mean?

two things that i noticed:

  1. if there is no command set (on the toolbar item), the popover automatically displays when clicking the toolbar button
  2. If there is a command set, then the user need to click and keep the toolbar button pressed until the popover shows.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文