js如何判断当前网络协议

2025年01月24日 建站教程

js如何判断当前网络协议,是http还是https?下面web建站小编给大家简单介绍一下!

示列代码:

var Protocol = window.location.protocol.split(':')[0];
if (Protocol === 'https') {
  console.log('当前协议是https')
}
else {
   console.log('当前协议是http')
}

扩展资料:

//当前域名 + 端口号
document.location.host

//当前的域名
document.location.hostname  

//当前的完整的URL
document.location.href  

//当前的端口号
document.location.port  

本文链接:http://so.lmcjl.com/news/21964/

展开阅读全文
相关内容