开发者

require javascript confirmation like alert()

Is there anyway to create an alert box, but with a more modern style? When an alert box is issued, the user can not use the browser until it is ack开发者_如何学JAVAnowledged (enter key or click OK). I would like to lock the browser in the same fashion, however use a custom made, better looking alert box. Is this possible with javascript?

Thanks

Edit: To clarify, by lock the browser I mean unable to change url, open new tab etc. The user needs to confirm before they can switch to another page


Yes. The kind of dialog you're referring to is a modal dialog. The basic principle of implementation is to simply cover the rest of the elements on the page with another element to render them unclickable.

Simply googling "javascript modal dialog" reveals a wealth of information; I could not hope to provide a comprehensive explanation in this small space.

[edited -Nickolay] Such dialog won't block further JavaScript execution as alert() does though, and it won't prevent the user from accessing the rest of the browser (other tabs and the Location bar). It's a good thing the user can continue to use the browser and it's one of the reasons such page-modal dialogs were created.


Yes, they are called "modal dialogs". JQuery has an excellent dialog widget that can be made modal as part of its JQueryUI library that can host just about any type of content, including forms.


See this one

Dialog

using jQuery

or

jQuery Alert Dialogs (Alert, Confirm, & Prompt Replacements)

Edit

To your edit: I don't think by using javascript you can prevent the user from typing it to the url bar or opening a new tab. And do avoid doing these sort of things that make a user hinder his normal action.


No, I don't think modal dialogs solves his question.(Not that I have a solution for this, but just to express my opinion). When you use modal dialogs, the only controls you can't access are those inside the web page but the controls of the browser can very well be accessed (ie. Menus, address bar);


This is not possible in javascript. You may use facebox-like containers, that simulates modal behavior, but there are not native modal, i.e. javascript code will not stop execution, when "modal window" is appear.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜