给网页HTML添加访问密码才能访问,三种代码方法 admin 2022-12-01 软件分享 热度: °C 选项 默认字体 ✓ 楷体 ✓ 霞鹜文楷体 ✓ 小 ✓ 中 ✓ 大 ✓ 阅读模式 编辑 为避免被陌生人访问,所以想给 html 页面加一个简单的密码,需要密码才能访问。其实加一段 JS 就可以!我最先开始贴的这段 JS,这段 JS 代码加在 body 和 /body 中间位置即可。方法一<script type="text/javascript"> function password() { var testV = 1; var pass1 = prompt(' 请输入密码 ',''); while (testV < 3) { if (!pass1) history.go(-1); if (pass1 == "www.ishiguang.cn") {// 初始密码 www.ishiguang.cn alert(' 密码正确 '); break; } testV+=1; var pass1 = prompt(' 密码错误 ! 请重新输入 :'); } if (pass1!="password" & testV ==3) history.go(-1); return " "; } document.write(password()); </script> <!-- 下面添加你要显示的内容或者代码 -->Plain text复制方法二<script type="text/javascript"> loopy() function loopy() { var sWord ="" while (sWord != "www.ishiguang.cn") {// 设置密码 初始密码 www.ishiguang.cn sWord = prompt(" 输入正确密码才能登陆 !") } alert(" 欢迎访问 ") } </script> <!-- 下面添加你要显示的内容或者代码 -->Plain text复制方法三<script type="text/javascript"> function password() { var testV = 1; var pass1 = prompt(' 请输入密码 :',''); while (testV < 3) { if (!pass1) history.go(-1); if (pass1 == "www.ishiguang.cn") {// 设置密码 初始密码 www.ishiguang.cn alert(' 口令正确,进行跳转 '); window.location.href="https://www.ishiguang.cn/";// 添加你要跳转的页面 break; } testV+=1; var pass1 = prompt(' 密码错误 ',''); } if (pass1!="password" & testV ==3) history.go(-1); return " "; } document.write(password()); </script>Plain text复制
评论区(3条评论)
୧(๑•̀⌄•́๑)૭ 中文测试
明文密码!好家伙
安全没有问题的,我自己测试过