HTML DOM Location protocol 属性
Location protocol 属性返回/设置与 URL 对应的协议字符串。协议可以设为“文件:”,“http:”,“https:”等。
语法
语法如下 −
- 返回值 protocol 属性
location.protocol
- Value of the protocol property set
location.protocol = protocolString
示例
让我们看一个设置 Location protocol 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<title>Location protocol</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>Location-protocol</legend>
<label for="urlSelect">Current URL:</label>
<input type="url" size="30" id="urlSelect" value="https://www.example.com:2544/aboutUs/CTO.htm">
<input type="button" onclick="getprotocol()" value="Get protocol">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var urlSelect = document.getElementById("urlSelect");
function getprotocol(){
divDisplay.textContent = 'URL protocol: '+location.protocol;
}
</script>
</body>
</html>输出
输出内容如下 −
单击“获取协议”按钮之前 −

单击“获取协议”按钮之后 −

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP