简单的JS输入密码即可查看显示网页内容代码四种方法,以下代码放在网页头部模版<head> </head> 标签内即可。新起点博客建议放在引入的js文件中可以防止有懂的人查看源代码看到。
代码一:
<script LANGUAGE="JAVASCRIPT"> loopy() function loopy() { var sWord ="" while (sWord != "123456") {//默认123456 sWord = prompt("输入正确密码登陆! ") } alert("身份识别......允许登陆") } </script>
代码二:
<script type="text/javascript"> loopy() function loopy() { var sWord ="" while (sWord != "123") {//初始密码123 sWord = prompt("输入正确密码才能登陆!") } alert("AH…欢迎光临!") } </script>
代码三:
<script type="text/javascript"> function password() { var testV = 1; var pass1 = prompt('请输入密码',''); while (testV < 3) { if (!pass1) history.go(-1); if (pass1 == "123456") {//初始密码123456 alert('密码正确!'); break; } testV+=1; var pass1 = prompt('密码错误!请重新输入:'); } if (pass1!="password" & testV ==3) history.go(-1); return " "; } document.write(password()); </script>
代码四(此方法可自定义对密码以后页面):
<script type="text/javascript"> function password() { var testV = 1; var pass1 = prompt('Sorry,该页只限熟人浏览,请输入密码:', ''); while (testV < 3) { if (!pass1) history.go(-1); if (pass1 == "123456") { //初始密码123456 alert('一看你就是自己人,口令正确!'); window.location.href = "http://www.henenseo.com"; //修改需要密码认证的网页 break; } testV += 1; var pass1 = prompt('朋友,密码不对!:(', ''); } if (pass1 != "password" & testV == 3) history.go(-1); return " "; } document.write(password()); </script>
评论前必须登录!
注册