在XUL JavaScript中使用10秒自动关闭提示警报框 [英] Close Prompt alert box automatically with 10Seconds in XUL JavaScript

查看:114
本文介绍了在XUL JavaScript中使用10秒自动关闭提示警报框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在XUL中使用的提示框:
function hintBoxes()

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秒内自动关闭此框(显示消息:此提示框将在1秒,然后在框内显示计时器)?

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");

如果要从警报框中返回值,例如按下了哪个按钮,可以这样做与讨论的 HERE

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中使用10秒自动关闭提示警报框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆