如何从http切换到https客户端
问题描述:
如何在客户端脚本中从http切换到https。请勿更改网址否则。它应该在https中不起作用。服务器对http和https的回复相同。我需要原始网址的其余部分保持不变。
How to switch from http to https in a client side script. Do not change the URL otherwise. It should do nothing in https. The server replies the same to http and https. I need the rest of the Original URL to stay intact.
http://example.com --> https://example.com
http://example.com/a --> https://example.com/a
http://example.com/b --> https://example.com/b
答
你可以使用javascript window.location.href属性重新加载页面,使用https url
you can use javascript window.location.href property to reload page with https url
// current url: http://example.
if(window.location.href.substr(0,5) !== 'https'){
window.location.href = window.location.href.replace('http', 'https');
} // new url: https://example.