是否可以模拟像'window.confirm()'这样的阻塞对话框? [英] Is it possible to simulate a blocked dialog like 'window.confirm()'?

查看:32
本文介绍了是否可以模拟像'window.confirm()'这样的阻塞对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想模拟块对话框,例如window.alert()window.confirm()window.prompt()DIV+JavaScript.使用回调函数似乎很容易.但是我想在显示确认对话框时阻止该过程.

I want to simulate a block dialog like window.alert(), window.confirm(), or window.prompt() with DIV+JavaScript. It seems easy using a callback function. But I want to block the process while the confirm dialog is shown.

也就是说,我想定义一个类似的函数:

That is to say, I want to define a function like:

var Alert = function(){ balabala };

在单击确定或取消后返回 truefalse.

which returns true or false after I click OK or Cancel.

编辑:

现在我定义了一个名为 Confirm() 的函数,现在我必须像

For now I defined a function called Confirm() and now I have to call it like

Confirm(*callback*);

在实现中,我显示了一个对话框,如确认,当点击 OK 时,将执行回调.我想知道是否可以重写它以便我可以像

and in the implementation I show a dialog like confirm and when OK is clicked the callback will be executed. I wonder whether it is possible to rewrite it so that I can call it like

if(Confirm()) {
    callback(); 
} else {
    balabala;
}

推荐答案

你不能阻止用户使用他们的浏览器 IE 切换标签页和在他们回到你的标签之前做其他事情,比如 警报() 调用确实如此.但是您可以阻止他们使用您页面上的任何内容,直到他们回答问题.你可以用一个绝对定位的 div 填充整个主体,该 div 的 z-index 大于页面的其余部分,并给你的弹出窗口一个更高的 z-index比那个并居中.

You can't block the user from using their browser IE switching tabs and doing other things on them before they come back to yours, like an alert() call does. But you can block them from using anything on your page until they answer the question. You can just fill the entire body with an absolute positioned div that has a z-index greater than the rest of your page, and give your popup a z-index one higher than that and center it.

当然,用户仍然可以使用 Chrome 开发者工具或 Firebug 之类的东西来删除您的阻塞 div,因此这不是一件安全的事情.

Of course a user can still use things like Chrome developer tools or Firebug to remove your blocking div, so it's not a secure thing.

编辑我误读了您的问题.您不关心在视觉上阻止页面,但希望使弹出窗口的返回值与脚本的其余部分同步,而不是与回调异步.我不知道该怎么做.

Edit I misread your question. You don't care about blocking the page visually but are wanting to make the popup's return value synchronous with the rest of your script instead of asynchronous with a callback. I'm not sure how to go about that.

也许这对你有用:https://developer.mozilla.org/en/Code_snippets/Threads#Waiting_for_a_background_task_to_complete

这篇关于是否可以模拟像'window.confirm()'这样的阻塞对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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