admin管理员组文章数量:1429882
I want to make a simple password protected link that enables users (with the correct password) to download a zip file. The link, as in the code below, is "folder/history.zip". The link is a simple text ("Open"), not a button. I don't have any experience with javascript. The problem is that the password protection does not work when I tried. I just want to know how can I edit the code below to make it work?.. I don't have any experience with javascript so I appreciate any help!
html:
<a href="folder/history.zip">open</a>
Javascript:
<SCRIPT type="text/javascript">
function passWord() {
var testV = 1;
var pass1 = prompt('Please Enter Your Password',' ');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1.toLowerCase() == "teacher") {
alert('You Got it Right!');
window.open('folder/history.zip');
break;
}
testV+=1;
var pass1 = prompt('Access Denied - Password Incorrect, Please Try Again.','Password');
}
if (pass1.toLowerCase()!="password" & testV ==3)
history.go(-1);
return " ";
}
</SCRIPT>
<CENTER>
<FORM>
<input type="text" value="Enter Protected Area" onClick="passWord()">
</FORM>
</CENTER>
I want to make a simple password protected link that enables users (with the correct password) to download a zip file. The link, as in the code below, is "folder/history.zip". The link is a simple text ("Open"), not a button. I don't have any experience with javascript. The problem is that the password protection does not work when I tried. I just want to know how can I edit the code below to make it work?.. I don't have any experience with javascript so I appreciate any help!
html:
<a href="folder/history.zip">open</a>
Javascript:
<SCRIPT type="text/javascript">
function passWord() {
var testV = 1;
var pass1 = prompt('Please Enter Your Password',' ');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1.toLowerCase() == "teacher") {
alert('You Got it Right!');
window.open('folder/history.zip');
break;
}
testV+=1;
var pass1 = prompt('Access Denied - Password Incorrect, Please Try Again.','Password');
}
if (pass1.toLowerCase()!="password" & testV ==3)
history.go(-1);
return " ";
}
</SCRIPT>
<CENTER>
<FORM>
<input type="text" value="Enter Protected Area" onClick="passWord()">
</FORM>
</CENTER>
Share
Improve this question
edited Jun 22, 2016 at 13:43
István
5,12710 gold badges40 silver badges68 bronze badges
asked Jun 22, 2016 at 13:04
Ched JoseChed Jose
1031 gold badge3 silver badges8 bronze badges
5
- 2 That is nowhere near a sufficient password protection. The file needs to be password protected on the server. As long as I can simply type the file's direct URL into my browser and download it, it is not protected. And both the direct URL and the password required for your little check here are plainly visible in the Javascript itself, which is visible to anyone bothering to look. – deceze ♦ Commented Jun 22, 2016 at 13:07
- I know it is not a good way to protect a link, but I am not looking for something more than this. I just want the password popup box to open. – Ched Jose Commented Jun 22, 2016 at 13:09
- Is there an error on the browser's JavaScript console? – David Commented Jun 22, 2016 at 13:19
- I am assuming that because, it is not working. When I test it and click on the link, the password popup box doesn't open. – Ched Jose Commented Jun 22, 2016 at 13:21
- Have you looked at your browser's Javascript console for errors? Typically you can open it with Ctrl+Alt+C... – deceze ♦ Commented Jun 22, 2016 at 13:23
1 Answer
Reset to default 3try the below code,
JS:
function passwd(){
var password = prompt('Enter the password to download the file:');
if(password.toLowerCase() == "teacher"){
window.open("folder/history.zip")
}else{
alert("incorrect password!! please try again");
}
}
HTML
<input type="button" value="download zip file" onClick="passwd()"/>
本文标签: javascriptPassword protected download linkStack Overflow
版权声明:本文标题:javascript - Password protected download link - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745467083a2659578.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论