您可以使用警报服务或从以下位置手动创建它chrome://global/content/alerts/alert.xul
:
function notify(title, msg, url, img, name, isClickable) {
var listener = {
observe: function(subject, topic, data) { // jshint ignore:line
// if (topic === 'alertclickcallback') {
// }
// if (topic === 'alertfinished') {
// }
},
};
try {
var alertWin = Cc['@mozilla.org/alerts-service;1'].getService(Ci.nsIAlertsService);
alertWin.showAlertNotification(img, title, msg, isClickable, url, listener, name);
}
catch (e) {
// fix for when alerts-service is not available (e.g. SUSE)
var ALERT_XUL = 'chrome://global/content/alerts/alert.xul';
var FF_WIN_OPTS = 'chrome,dialog=yes,titlebar=no,popup=yes';
// arguments[0] --> the image src url
// arguments[1] --> the alert title
// arguments[2] --> the alert text
// arguments[3] --> is the text clickable?
// arguments[4] --> the alert cookie to be passed back to the listener
// arguments[5] --> the alert origin reported by the look and feel
// 0: bottom right.
// 2: bottom left
// 4: top right
// 6: top left
// arguments[6] --> bidi
// arguments[7] --> lang
// arguments[8] --> replaced alert window (nsIDOMWindow)
// // i. e. previous alert
// arguments[9] --> an optional callback listener (nsIObserver)
// arguments[10] -> the nsIURI.hostPort of the origin, optional
var winArgs = [img, title, msg, isClickable, url, 2, null, null, null, listener, name];
// aParentwindow, aUrl, aWindowName, aWindowFeatures, aWindowArguments (nsISupports)
var win = Services.ww.openWindow(null, ALERT_XUL, '_blank', FF_WIN_OPTS, null);
win.arguments = winArgs;
}
}