在 XUL JavaScript 中用 10 秒自动关闭提示警报框

发布于 2024-12-01 14:16:46 字数 975 浏览 2 评论 0原文

这是我在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秒内自动关闭此提示框(并显示消息:此提示框将在1O秒后关闭,并且在盒子本身中显示计时器)?

如何将该框放置在系统的角落显示?

我在 Mozilla 提示服务中没有找到任何计时器详细信息

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.

}

I have taken the above function from this website:
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService#alertCheck_example

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?

I don't find any timer details in Mozilla prompt service

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你げ笑在眉眼 2024-12-08 14:16:46

我认为内置提示不可能做到这一点,但您可以使用自定义提示窗口轻松做到这一点。

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 窗口创建一个 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");

如果您想从警报框中返回一个值,例如按下了哪个按钮,您可以按照与讨论此处

我不确定模态窗口的位置,因此您可能想在单独的问题中询问。

I don't think this is possible with the build in prompt but you can easily do so with a custom prompt window.

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) 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) 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文