Tuesday, December 11, 2007

Make a "toaster" in firefox

(Refer to http://developer.mozilla.org/en/docs/nsIAlertsService#Example .)
The nsIAlertsService works great on Mac (firefox 3 only) and Windows.

Sample:

var alertsService = Components.classes["@mozilla.org/alerts-service;1"]
.getService(Components.interfaces.nsIAlertsService);
alertsService.showAlertNotification(
"chrome://mozapps/skin/downloads/downloadIcon.png",
"Alert title", "Alert text goes here.",
false, "", null);


But in firefox 2, we have to use showPopup() and hidePopup() as workaround:

popBox.showPopup(pop, xPos, yPos, 'popup', 'bottompright');
setTimeout(function(popBox){
popBox.hidePopup(pop);
}, 2000, popBox);

No comments: