How to create a private page

How to create a private page

In that article we’ll talk about how we can create private page on your site. Private page is a page that can be entered if user knows a password that you can set. The main advantage of such script is that it can be put in any place of the document. Script will start working when it’ll be its turn, i.e. if your page has the following view:

<HTML>
<Head>
<title>Password</title> 
</head> 

Text of the link
<Script language=JavaScript> script body </script>
Text of the link
</html>

So, user clicks the link for opening the page and page starts loading. When it reaches the place where your script is set loading stops and appears a pop-up message with the following text: “That page is closed for the public viewing, if you have access rights you can enter. Otherwise, please, leave the page.” User clicks “OK” and there appears a password field. If user enters a proper password page continuous loading, if not there appears new pop-up message with text: “Enter when you get the access rights”. After that there opens the page that is pointed in the script in the case of the wrong password.

So, open any script editor and find the following lines:

<body lang=RU style="tab-interval:35.4pt">
<div class=Section1>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>

Now you have to write the following code before the «/div» tag:

<script language="JavaScript">
// It is obligatory condition, 
because browser must know the language you use

alert (That page is closed for the public viewing, 
if you have access rights you can enter. 
Otherwise, please, leave the page ")
// alert() – it is a warning that can be edited by you
//It is a primary message, 
i.e. user will see it before script starts working

pass = prompt(If you don’t have a password press Cancel:");
if (pass=="password") { alert("Welcome") } else 
{ alert(Enter when you get the access rights"),
top.location.href="index.html" }
</Script>
//Means script working finishing

if (pass=='password') { alert('Welcome') } else { alert(Enter when you get the access rights'), top.location.href="index.html" } That line is complicated enough that’s why let’s view it step by step.

if (pass=='password'). It means that if that password entered by user coincides with the password in inverted commas after pass system must show message “Welcome” and keep on loading the page. And if passwords are not equal there should appear another message and using top.location.href=”” you should go to the index.html page, i.e. top.location.href="index.html".

= = signs after word pass mean that program will check the entered value, and if you write only one = sign script will consider the entered word as a password. Such situation can entail serious consequences. Now our script will have the following view:

<script language="JavaScript">
alert(That page is closed for the public viewing,if you have access rights you can enter. 
Otherwise, please, leave the page ")
pass = prompt(If you don’t have a password press Cancel:");
if (pass=="password") { alert(Welcome) }
else { alert(Enter when you get the access rights "),
top.location.href="index.html" }
</script>

That code you can insert into the any page you want to consist the password.


 

  • Top