JavaScript |位置协议属性

什么是礼节? 网络协议定义了网络设备之间通信的规则和约定。通过采用这些规则,两个设备可以相互通信并交换信息。

null

语法:

location.protocol

属性:

  • ftp: 文件传输协议(FTP)是一种标准网络协议,用于在计算机网络上的客户端和服务器之间传输计算机文件。
  • http: 超文本传输协议(HTTP)是一种用于分布式系统的应用协议。
  • https: 超文本传输协议安全(HTTPS)是用于安全通信的超文本传输协议(HTTP)的扩展,广泛应用于互联网。
  • 文件: 它用于文件或本地服务器系统。
  • 邮寄地址: 它用于邮件系统。

返回值: protocol属性返回当前URL的协议,包括冒号(:)。

下面的例子说明了位置。JavaScript中的协议属性: 例子:

<!DOCTYPE html>
<html>
<head>
<title>Location protocol property</title>
<style>
#Gfg {
position: center;
width: 220px;
height: 50px;
color: green;
}
</style>
<script>
// Function that tells the Protocol
// of current url.
function Protocol() {
var gfg = location.protocol;
alert( "protocol is: " + gfg);
}
</script>
</head>
<body>
<div id = "Gfg" >
<h1>GeeksforGeeks</h1>
</div>
<p>Click to know the protocol of current URL.</p>
<button onclick = "Protocol()" >Protocol</button>
</body>
</html>


输出: protocol

© 版权声明
THE END
喜欢就支持一下吧,技术咨询可以联系QQ407933975
点赞10 分享