In some cases, the password protection may conflict
with external JavaScript .js files, especially with JavaScript
based web menu.
Upgrade: In version
4.8, HTML Password Lock adds a new option "Generate a standalone
login file for each locked HTML file" in Step 3,
Advanced Options dialog. With this option,
these kinds of webpages can be password protected with HTML
Password Lock perfectly. For more details, please refer to:
How to password protect HTML
page with Frontpage extension based web form or Javascript based
web menu?
The best way is to remove the JavaScript web menu from the
locked HTML file, but if you don't want to do that, there are
still three ways to solve this problem.
First method:
Firstly, you can simply move the scripts from the external
.js file to the HTML file itself to solve the problem.
For example, a reference to external .js file in your HTML
file may look like this:
<script language="javascript" src="myscript.js"></script>
Please check your html file, if it contains such references,
please move the javascripts from the external .js file to the
html file itself, then this problem will be fixed.
That is, change the line to:
<script language="javascript">
(move scripts from file "myscript.js"
to here)
</script>
Second Method:
If the above method does not fix the problem, you can try to
fix the problem in this way:
1. Suppose the HTML need for protection is http://www.yoursite.com/member.html
. You can create a web page which will automatically redirect
to the member page, and lock this web page. The code of this
web page may look like below, please change the filename "http://www.yoursite.com/member.html"
to your own flename. Please DO NOT lock the member page.
<HTML>
<HEAD>
<TITLE>Title</TITLE>
</HEAD>
<BODY>
<script language="JavaScript">
document.cookie='mtopverify=valid;path=/';
this.location.href="http://www.yoursite.com/member.html"
</script>
If the page does not redirect automatically, please <a href="http://www.yoursite.com/member.html">click
here</a>
</BODY>
</HTML>
Suppose the new page you created with above code is login.html,
then you need to lock this new file with HTML Password Lock
and upload the locked page to your web server as http://www.yoursite.com/login.html
. After your visitor views this page, he will
see the login box, after he login, he will be automatically
redirect to the page http://www.yoursite.com/member.html,
the real member page.
2. A possible problem of the above method is that, a visitor
may directly type in the URL address of the member page or bookmarking
the member page and bypass the password protection. To stop
this and force the visitor to the login page when they directly
type in or bookmarking the member page url, please add below
codes to the member page, please change the http://www.yoursite.com/login.html
to your own login filename created in previous step.
<script language="JavaScript">
function checkvalid()
{
if (document.cookie.length<0) return false;
begin=document.cookie.indexOf('mtopverify=');
if (begin==-1) return false;
begin=begin+11;
end=document.cookie.indexOf(';',begin);
if (end==-1) end=document.cookie.length;
result=unescape(document.cookie.substring(begin,end));
if (result=="valid") return true; else return false;
};
var bRet = checkvalid();
if (!bRet) this.location.href="http://www.yoursite.com/login.html";
</script>
Third Method:
If above can not be done, you can use the third way. In this
way, you can remove the JavaScript web menu from the locked
page, and embed the locked page to your other web pages with
IFRAME.
Below is the example for how to use IFRAME to embed a locked
page. |