这是我在XUL中的提示警告框函数:函数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
如何在10秒内自动关闭此框(显示消息:此提示框将在10秒内关闭,并在框中显示计时器)?
如何将此框定位到显示在系统的角落?
我在Mozilla提示服务中找不到任何计时器详细信息
发布于 2011-08-26 16:49:41
我认为使用build in prompt不可能做到这一点,但您可以使用自定义提示窗口轻松完成此操作。
1)创建XUL对话框alert_prompt.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"
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窗口alert_prompt.js创建一个Javascript文件
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)不像前面那样显示警报提示,而是使用以下语句:
openDialog("chrome://hello/content/alert_prompt.xul","alert_prompt","modal");如果您想从警告框中返回一个值,例如按下了哪个按钮,您可以使用与讨论的HERE相同的方法来完成此操作
我不确定模式窗口的位置,所以你可能想在一个单独的问题中问这个问题。
https://stackoverflow.com/questions/7196269
复制相似问题