Share this page 

Protect a page access with JAVASCRIPT onlyTag(s): HTML/CSS

If the password protection mechanism provided by the Web server is not available, a simple way to protect a page with JAVASCRIPT is to match the user password with the filename to be loaded.
function login() {
   if (validLogin()) {
      password = document.userInfos.password.value;
function validLogin() {
   if (isBlank(document.userInfos.password.value)){
      alert("Can't be blank");
      return false;
   return true;      
function isBlank(s) {
   return (s == "");

<BODY onLoad="document.userInfos.password.focus();">
<H1><CENTER>Identification </H1></CENTER>
<FORM  NAME=userInfos>
<TR><TD>Password: </TD><TD> 
<INPUT TYPE="password" NAME=password LENGTH=20>
<TR ALIGN=center>
<INPUT TYPE="button" VALUE="Ok" onClick="login()">