Skip to content

Latest commit

 

History

History
31 lines (19 loc) · 874 Bytes

get-protocol.md

File metadata and controls

31 lines (19 loc) · 874 Bytes
标题 标签
getProtocol(获取当前页面的协议) browser(浏览器)

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

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

ts 代码如下:

调用方式:

getProtocol(); // 'https:'

应用场景

以下是一个实战示例:

结果如下:

<iframe src="codes/javascript/html/get-protocol.html"></iframe>