How to fix the problem with JavaScript web menu?

In some cases, the password protection may conflict with external JavaScript .js files, especially with a JavaScript based web menu.

Upgrade: In version 4.8, HTML Password Lock added a new "Generate a standalone login file for each locked HTML file" option in Step 3, Advanced Options dialog. With this option, these web pages can be password protected with HTML Password Lock perfectly. For more details, please refer to:

How to password protect HTML page with a 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.

Solution 1:

To solve the problem, simply move the scripts from the external .js file to the HTML file itself to solve the problem.

For example, a reference to an 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 above to:

<script language="javascript">
(move all scripts here from file "myscript.js")
</script>

Solution 2:

If the above method does not fix the problem, you can try fixing it as following:

1. Suppose the HTML that needs for protection is http://www.yoursite.com/member.html. You can create a web page that will automatically redirect to the member page, and lock this web page. The code for this web page might read as shown below, provided you change the filename "http://www.yoursite.com/member.html" to your own filename. Please DO NOT lock the member.html 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 the above code is login.html. In that case, 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 . When your visitor views this page, he will see the login box, after a correct login, he will be automatically redirected to the page http://www.yoursite.com/member.html, the real member page.

2. The flaw in this solution is that a visitor might try to access directly the member page by typing in the URL address or bookmarking the member page, thus bypassing the password protection. To stop this and force visitors to the login page when they directly type in or bookmark the member page URL, please add the codes shown below to the member page, changing the http://www.yoursite.com/login.html to your own login filename created in the 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>

Solution 3:

If the above won't do it, you can use a third method. Remove the JavaScript web menu from the locked page, and embed the locked page to your other web pages with IFRAME.

The following explains how to use IFRAME to embed a locked page.

This is to display a JavaScript based web menu:

 

This is about how to use IFRAME to embed a locked web page:

Source code:

The file example5.htm is the actual locked page.

Below is the display of example5.htm (username: mtopsoft, password: 123456). It really looks like it's part of the current page, but it isn't. It's just a standalone page named"example5.htm".

 

Search This Site:

   Advanced

Main

HTML Password Lock
Screenshots
Order Now!
  Download Now

Help

Online Help
Quick Start
FAQ

Online Example

Single Password
Multi-Users/Passwords

Related Products

Search Engine Composer
Web Button Menu Maker

Who likes our products:

Rated 4.5 stars at SnapFiles

Pop at Cnet Download.com

Rated 5 Stars at The File Transit!

 
Home | Download | Order Now | Contact us | Links
ęCopyright Mtopsoft.com All Rights Reserved.