(已解决)页面刷新后如何重定向回登录页面?

问题描述 投票:0回答:2

刷新后是否可以重定向回登录页面?

我正在使用此密码保护代码。

https://github.com/matteobrusa/Password-protection-for-static-pages

因为我部署在netlify中。它不支持.htaccess

我已经尝试过此代码。

window.onload = function () {
  window.location = "../index.html";
}

但是在页面加载时,它会自动重定向到登录页面。

*我是新来的

谢谢,:)

javascript password-protection
2个回答
0
投票

代替window.location使用window.location.href


0
投票

我找到了解决方案。但不适用于歌剧

编辑:适用于歌剧

window.onbeforeunload = function() { 
    window.setTimeout(function () { 
        window.location = 'index.html';
    }, -1); 
    window.onbeforeunload = null; // necessary to prevent infinite loop, that kills your browser 
}

我从]找到了这个解决方案>

https://stackoverflow.com/a/33344421/13501652

© www.soinside.com 2019 - 2024. All rights reserved.