问题描述
这是我在 XUL 中的提示框功能:函数 promptBoxes()
This is my prompt alert box function in XUL:function promptBoxes()
{
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var check = {value: false}; // default the checkbox to false
var flags = prompts.BUTTON_POS_0 * prompts.BUTTON_TITLE_Ok+
prompts.BUTTON_POS_1 * prompts.BUTTON_TITLE_IS_STRING;
var button = prompts.confirmEx(null, "Title of this Dialog", "What do you want to do?",
flags, "", "Cancel", "", null, check);
// 0, 1, or 2.
}
我从这个网站上获取了上述功能:https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService#alertCheck_example
I have taken the above function from this website:https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService#alertCheck_example
我怎样才能在10秒内自动关闭这个框(有显示信息:这个提示框会在1O秒内关闭并在框中显示计时器)?
How could I close this box automatically within 10seconds(with display message: this prompt box will close in 1O seconds and display the timer in the box itself)?
如何将这个框定位到系统的一角?
How can position this box to shown at the corner of the system?
我在 Mozilla 提示服务中找不到任何计时器详细信息
I don't find any timer details in Mozilla prompt service
推荐答案
我认为内置提示无法实现这一点,但您可以使用自定义提示窗口轻松实现.
I don't think this is possible with the build in prompt but you can easily do so with a custom prompt window.
1) 创建一个 XUL 对话框 alert_prompt.xul 如下:
1) Create a XUL dialog alert_prompt.xul as follows:
<?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"
buttons="accept,cancel"
buttonlabelcancel="Cancel"
buttonlabelaccept="Save"
height="140"
width="250"
ondialogaccept="return alert_prompt.doOK();"
ondialogcancel="return alert_prompt.doCancel();">
<script type="application/javascript" src="chrome://hello/content/alert_prompt.js"/>
<dialogheader title="Timer Alert Prompt"/>
<label id="result" value="This prompt will close in 10 seconds." align="center"/>
</dialog>
2) 为这个 XUL 窗口创建一个 Javascript 文件 alert_prompt.js
2) Create a Javascript file for this XUL window alert_prompt.js
var alert_prompt = {
init : function()
{
alert_prompt.timedCount(0);
},
timedCount : function(c)
{
//update the prompt message
document.getElementById('result').value="This prompt will close in "+ (10 - c) + " seconds.";
//if 10 seconds are over close the window
if(c == 10)
{
window.close();
}
//update the counter
c=c+1;
//use the timer
t=setTimeout(
function()
{
alert_prompt.timedCount(c);
},1000)
},
doOK : function()
{
//code that you want to run when save button is pressed
return true;
},
doCancel : function()
{
//code that you want to run when cancel button is pressed
return true;
},
};
window.addEventListener("load", alert_prompt.init, false);
3) 使用此语句代替之前显示的警报提示:
3) Instead of showing the alert prompt as earlier use this statement:
openDialog("chrome://hello/content/alert_prompt.xul","alert_prompt","modal");
如果您想从警报框中返回一个值,例如按下了哪个按钮,您可以按照与讨论相同的方式进行操作 此处
If you want to return a value from the alert box such as which button was pressed you can do so in the same way as discussed HERE
我不确定模态窗口的位置,所以你可能想在一个单独的问题中提出这个问题.
I am not sure about the positioning of a modal window so you may want to ask that in a separate question.
这篇关于在 XUL JavaScript 中使用 10Seconds 自动关闭提示警告框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!