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