0

如何加密博客页面的密码保护?或者添加一个函数可能......所以它在代码中不会那么明显。

无论如何我可以添加一些CSS设计吗?或使其在屏幕中央弹出。

<!-- paste this password form in your blogger post/page -->
<script language="JavaScript">
var password = ' '
password=prompt('This is password protected page, please enter password to continue.','');
if (password != 'password') {
location.href='https://errorpage.blogspot.com/404';
}
</script>
<!-- end password -->

ps:我是 JavaScript 新手,还在学习中...

图片:https ://i.imgur.com/oe2WiYc.png

这就是表单的样子,但任何人都可以访问代码 (Ctrl + U) 并查看密码...

4

1 回答 1

1

您可以通过 css 隐藏整个页面,然后使用 js 显示它。在 /head 之前输入下面的代码,看看魔法

<div style='position:fixed;overflow:none;height:100%;bottom:0;width:100%;top:0;display:table;text-align:center;background:hsla(0, 0%, 0%, 0.72)' id='passward-protected'>
<div style='display:table-cell;vertical-align:middle'>
This Page is password protected
<button onclick='enterpass()'>Enter Password</button>
</div>
</div>


<!-- paste this password form in your blogger post/page -->
<script language="JavaScript">
function enterpass(){
var password = ' '
password=prompt('This is password protected page, please enter password to continue.','');
if (password == 'password') {
document.getElementById('passward-protected').style.display='none';
}else{
alert('Wrong Password')
}
}
</script>

于 2020-04-20T11:46:36.707 回答