Skip to content
2010年10月4日 / island205

[译].Google Chrome extensions(实验室).浏览器交互.事件

Events

     一个事件是一个对象,相关事件发生的时候将会得到报告。这是一个运用chrome.tabs.onCreated事件报告一个新标签的创建:

   1:  chrome.tabs.onCreated.addListener(function(tab) {
   2:    appendToLog('tabs.onCreated --'
   3:                + ' window: ' + tab.windowId
   4:                + ' tab: '    + tab.id
   5:                + ' index: '  + tab.index
   6:                + ' url: '    + tab.url);
   7:  });

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

如例所示,使用addListener()来注册报告。传给addListener()的参数一般是一个函数,用来处理事件,但是这个函数的参数依赖于需要处理事件的类型。查看文档更多关于chrome.tabs.onCreated。这个函数只有一个参数:一个Tab对象拥有新建的tab的细节信息。

方法

      对于一个Event对象你可以调用如下方法:

   1:  void addListener(function callback(...))
   2:  void removeListener(function callback(...))
   3:  bool hasListener(function callback(...))

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

目录:http://island205.coolpage.biz/?p=37

原文链接:http://code.google.com/chrome/extensions/events.html

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: