Skip to content

Latest commit

 

History

History
25 lines (16 loc) · 621 Bytes

getProtocol.md

File metadata and controls

25 lines (16 loc) · 621 Bytes
标题 标签
getProtocol(获取当前页面的协议) browser(浏览器)

获取当前页面使用的协议。

  • 使用 Window.location.protocol 获取当前页面的协议(http: 或 https:)。
const getProtocol = () => window.location.protocol;

调用方式:

getProtocol(); // 'https:'

应用场景

结果如下:

<iframe src="codes/javascript/html/getProtocol.html"></iframe>