Display multi-line notifications

I just started playing with Mozilla Jetpack and I really like it. I wrote a little code that displays an icon in the status bar, which when clicked triggers a notification:

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}); }); } }); 

Since the text is very long in this example, the notification is as follows:

Jetpack Notice http://img33.imageshack.us/img33/7113/jetpack.png

I want to split the notification text into four different lines when they are displayed so that the notification window is higher and narrower. How can I do it?

Edit 1 (Thanks to Rudd Zwolinski ):

I tried, but this does not help:

 var myBody = line1 + '\n' + line2 + '\n' + line3 + '\n' + line4; 

Edit 2 (thanks Ólafur Waage ):

It does not help:

 var myBody = line1 + '<br />' + line2 + '<br />' + line3 + '<br />' + line4; 

Edit 3 (Thanks to Matt ):

Even this does not help:

 var myBody = line1 + "\n" + line2 + "\n" + line3 + "\n" + line4; 
+7
javascript jquery firefox-addon firefox-addon-sdk
source share
3 answers

Unfortunately, the generated alert does not allow new lines to pop up toast windows in Windows. According to the Jetpack API:

In the end, this object will be the end - all simple communication with your users. Notification bars, transparent messages, Growls, doorknob messages, etc. everyone will go here. So far, these are just simple notifications.

As shown in the source code , the jetpack.notifications.show method makes a call to Mozilla nsIAlertsService , which prevents multiple lines from being used for Windows pop-ups.

The upside is that the API indicates that in the future you will have much more control over alerts, but for the preliminary version you will need to keep the notification text to a minimum.

+8
source share

I cannot verify this because I am on a mac and receive Growl notifications from jetpack.notifications.show and Growl limits the width, but try changing myBody to this:

 var myBody = line1 + '\n' + line2 + '\n' + line3 + '\n' + line4; 

Line breaks are displayed to me, so this may be what you are looking for.

EDIT . This does not work for Windows toast notifications, so it does not answer the question. However, it will display newlines in Growl notifications for Mac OS X , so I leave this answer.

+1
source share

IIRC is correct, jetpack uses JavaScript and HTML, so just try adding <br /> between the lines.

0
source share

All Articles