views:

357

answers:

5

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 acknowledged (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

+1  A: 

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.

rahul
Is the down vote for using jQuery in my answer?
rahul
+3  A: 

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.

Soviut
i don't know why these days Javascript simply means Jquery. :D
Rakesh Juyal
Because it makes development a lot easier without having to handle browser dependancies.
rahul
+7  A: 

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.

Thom Smith
(The answer to the OP's edit is "No" though)
Nickolay
Thanks for the answer, it pretty much answers for before and after I edited.
Lobe
I am sort of glad that there isn't a way, as while the application I am working on is a novelty one, I'd hate to think what the web would be like if this was able to be done
Lobe
A: 

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.

Anatoliy
+1  A: 

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

junmats