ele*_*n81 10 javascript jquery firefox-addon firefox-addon-sdk
我刚开始玩Mozilla Jetpack,到目前为止我喜欢它.我写了一个小代码,在状态栏中显示一个图标,点击后会显示一个通知:
var myTitle = 'Hello World!';
var line1 = 'I am the very model of a modern Major-General,';
var line2 = 'I\'ve information vegetable, animal, and mineral,';
var line3 = 'I know the kings of England, and I quote the fights historical,';
var line4 = 'From Marathon to Waterloo, in order categorical.';
var myBody = line1 + ' ' + line2 + ' ' + line3 + ' ' + line4;
var myIcon = 'http://www.stackoverflow.com/favicon.ico';
jetpack.statusBar.append({
html: '<img src="' + myIcon + '">',
width: 16,
onReady: function(doc) {
$(doc).find("img").click(function() {
jetpack.notifications.show({title: myTitle, body: myBody, icon: myIcon});
});
}
});
Run Code Online (Sandbox Code Playgroud)
由于此示例中的文本很长,因此通知如下所示:
Jetpack通知http://img33.imageshack.us/img33/7113/jetpack.png
我想在显示时将通知文本拆分为四条不同的行,以便通知框更高更窄.我该怎么做呢?
编辑1(感谢Rudd Zwolinski):
我试过了,但这没有帮助:
var myBody = line1 + '\n' + line2 + '\n' + line3 + '\n' + line4;
Run Code Online (Sandbox Code Playgroud)
编辑2(感谢ÓlafurWaage):
这也无济于事:
var myBody = line1 + '<br />' + line2 + '<br />' + line3 + '<br />' + line4;
Run Code Online (Sandbox Code Playgroud)
编辑3(感谢Matt):
即使这样也无济于事:
var myBody = line1 + "\n" + line2 + "\n" + line3 + "\n" + line4;
Run Code Online (Sandbox Code Playgroud)
不幸的是,创建的警报不允许在Windows中使用toast popup的新行.根据Jetpack API:
最终,这个对象将是与用户轻松沟通的最终目标.通知栏,透明消息,Growls,门把手消息等都将在这里完成.目前,它只是简单的通知.
如源代码所示,该jetpack.notifications.show方法调用Mozilla nsIAlertsService,它不允许多行用于Windows Toast弹出窗口.
好处是API表明您将来可以更好地控制警报,但对于预发布版本,您必须将通知文本保持在最低限度.