Is there any way to detect HTTP or HTTPS and then force usage of HTTPS with JavaScript?
I have some codes for detecting the HTTP or HTTPS but I can't force it to use https:
.
I'm using the window.location.protocol property to set whatever the site is to https:
then refresh the page to hopefully reload a new https'ed URL loaded into the browser.
if (window.location.protocol != "https:") {
window.location.protocol = "https:";
window.location.reload();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…