How to switch from http to https client side [closed]

六眼飞鱼酱① 提交于 2019-12-22 12:29:30

问题


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

回答1:


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.


来源:https://stackoverflow.com/questions/40562181/how-to-switch-from-http-to-https-client-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!