As anything involving Javascript can be nullified simply by disabling Javascript in the browser, you need to use a server-side solution such as htaccess.
You can restrict access to authorised
persons simply by redirecting to a page which has the same url as the "password" entered.
Code:
Enter password <input type = "password" id = "pwd" onblur = "redirect()">
<script type = "text/javascript">
function redirect() {
var url = document.getElementById("pwd").value; // example: secret
url = url + ".html";
window.location.href = url; // secret.html;
}
</script>
Another way to restrict access to certain machines is to store the redirect url (var myurl = "secret.html") in an external .js file on those machines you want to authorise, and then simply
<script type = "text/javascript">
window.location.href = myurl;
</script>
This assumes you have physical access to the machines so that you can install the .js file. This method is not secure but obviously only machines on which the redirect url is stored will be able to make the redirect. This assumes that the url is unguessable and is not "leaked" by your users. People who know the url can obviously go there directly. You will probably have the change the url fairly frequently.
Notice that you must redirect
to the secret page from the initial page, not the other way round (not redirect from the secret page to "blocked.html").
But does it
really matter if some unauthorised person is able to access your page?