如何使用 JavaScript XUL 在警报或 propmts.alert 中添加图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7203372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add image in alert or in propmts.alert using JavaScript XUL
提问by linguini
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService#prompt_examplehttps://developer.mozilla.org/en/Code_snippets/Alerts_and_Notifications
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService#prompt_example https://developer.mozilla.org/en/Code_snippets/Alerts_and_Notifications
Mozilla XUL offers various types of alert and notification box messages. But, still why can't we have an image in the alert message?
Mozilla XUL 提供各种类型的警报和通知框消息。但是,为什么我们不能在警报消息中显示图像?
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
prompts.alert(null, contact, "No Email Address")
The above code to display an alert with custom title message. When we check the nsIPromptService
, it give various options but still there is no possibility of adding an image according to my knowledge.
上面的代码显示带有自定义标题消息的警报。当我们检查 时nsIPromptService
,它提供了各种选项,但据我所知仍然无法添加图像。
When we check the popup in XUL, we can add an image
but the alert will display in the corner of the system because it's using the nsIAlertsService
and the display of this pop-up is platform independent.
当我们在 XUL 中检查弹出窗口时,we can add an image
但警报会显示在系统的角落,因为它使用的是nsIAlertsService
并且此弹出窗口的显示与平台无关。
Would it be possible to have an image in the alert box or in the prompts.alert box using JavaScript in XUL?
是否可以在 XUL 中使用 JavaScript 在警告框中或 prompts.alert 框中显示图像?
回答by Amulya Khare
Why don't you use a custom alert dialog as discussed HERE?
为什么不使用此处讨论的自定义警报对话框?
XUL for the alert with image may be like:
带有图像的警报的 XUL 可能类似于:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
<dialog id="alertprompt" title="Alert"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
buttons="accept"
buttonlabelaccept="Ok"
height="160"
width="260"
ondialogaccept="return alert_prompt.doOK();">
<script type="application/javascript" src="chrome://hello/content/alert_prompt.js"/>
<label id="title" value="Title may go here!" align="center" class="header"/>
<html:table>
<html:tr>
<html:td>
<html:img src="Firefoxlogo.png" width="30" height="30"/>
</html:td>
<html:td>
<label id="result" value="This place will display your message." align="center"/>
</html:td>
</html:tr>
</html:table>
</dialog>
It will look something like:
它看起来像:
Does it meet your requirement?
它符合你的要求吗?