如何从http切换到https客户端 [英] How to switch from http to https client side

查看:150
本文介绍了如何从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.

这篇关于如何从http切换到https客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆