在XUL JavaScript中10秒自动关闭提示警报框
Close Prompt alert box automatically with 10Seconds in XUL JavaScript
这是我在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提示服务中找不到任何定时器细节
我不认为这是可能的内置提示,但你可以很容易地做到这一点,自定义提示窗口
1)创建XUL对话框alert_prompt。
<?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
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");
如果你想从警告框返回一个值,比如哪个按钮被按下了,你可以用同样的方式来做,这里
我不确定模态窗口的定位,所以你可能想在一个单独的问题中问。
相关文章:
- 提示使用服务器端事件处理程序激活JavaScript
- Javascript 可选类型提示
- 单击按钮后启动javascript提示
- 如何在 JavaScript 和 HTML 中更改对输入框的提示响应
- 使用CSS/JavaScript更改剑道图工具提示文本颜色
- 将javascript应用程序迁移到使用AMD的提示(例如requirejs)
- 通过提示中的循环触发iFrame中的输入按钮(JavaScript)
- 如何强制用户在javascript提示中输入值
- 如何在seleniumwebdriver中执行javascript提示并等待接受输入
- 在不使用javascript的情况下,可以在表单字段中设置文本占位符(以提示最终用户插入特定格式)
- 带有关闭按钮的javascript/jquery响应工具提示
- Google图表HTML工具提示,其中包含javascript onclick事件
- 在工具提示Javascript中插入HTML
- 添加一个不带jquery的工具提示-Javascript
- 工具提示JavaScript在未给出“title”属性时会中断以下表单元素
- 获取被用户终止的“提示”;javascript例外
- 验证提示javascript
- 如何修改我的工具提示javascript
- jQuery占位符/提示JavaScript保持提示的焦点
- 工具提示Javascript旋转不工作