Prompting the user for a username & password (pop-up box)

Hi everybody,

If you’ve ever tried to enter the Cpanel for your site, you’ve probably encountered a pop-up dialog box which prompts for username & password. If you haven’t, please take some time to see ours: http://cpanel.chaptaco.com/

The question is: “how this is done?” Are these kind of prompt boxes created using JavaScript at all? As far as I know, JavaScript methods like “prompt()” ask only for one parameter not for two simultaneously. If this is done via JavaScript would you kindly tell me how and using which object and which method?

I do appreciate your taking time to help a poor buddy!:confused:

It’s not done with javascript. It’s called HTTP Authentication and can be set up either in your server side programming language (PHP, ASP, etc) or in the web server (Apache, IIS, etc).

One option is to put the code for the pop-up (username/password textboxes etc) in a separate html or php file and then use window.open() with appropriate fixed dimensions to open that separate file in a new pop up window.

Dear forum admin,

thank you very much for your fast reply. That’s actually what I expected and I’ve done it once to protect a directory on our website. The authentication is set up on the web server which affects the .htaccess file which is responsible for directory configurations such as access permissions. However, my question is the prompt box itself. As you can see the box is quite persistent and never loses focus unless you hit the cancel button. That’s what I’ve seen only in Javascript boxes and I think is up to the browser not to the server. If you have any additional information about how to set up the prompt box itself, I’d be grateful if you let me know. Thanks in advance.

I’m not the forum admin, just a moderator :slight_smile:

Anyway, it sounds like you’re looking for javascript modal windows. Some examples can be found here: http://www.designlabelblog.com/2009/03/20-ways-to-create-javascript-modal.html

Thanks for your taking time to answer my question Kalon. The option you are talking about is very good for customizing the look and feel of the box we are to push to the user. However, there are many problems associated with pop-up windows. Two of them which may call the usability of this particular situation into question are:

  1. Most modern browsers block pop-up windows unless the user allows them to pop up. Some careless users may actually ignore browser messages and never see the box.

  2. Unlike JavaScript prompt, confirm and alert boxes which are quite persistent and never lose focus and don’t even allow another browser tab to receive focus until they get their answer, pop-up windows can easily lose focus as a result of clicking somewhere else on the screen. So, they may go behind other windows and simply be ignored.

For the reasons above, your solution can not replace the prompt boxes I’m after.

Anyway, thank you again for answering my question and if you have some additional information, I’d be glad and grateful to know.

Wow, you’re very quick to reply. Yes I think several modal windows on the page you mentioned can be used to serve this purpose.

Thank you very much.

Of course then the 6-10% of people without JavaScript will have no way to access it. You are better off using HTTP Authentication that works for everyone.