Location protocol 속성은 URL에 사용된 프로토콜에 해당하는 문자열을 반환/설정합니다. 프로토콜은 'file:', 'http:', 'https:' 등으로 설정할 수 있습니다.
구문
다음은 구문입니다 -
- 프로토콜의 반환 값 재산
location.protocol
- 프로토콜의 가치 속성 집합
location.protocol = protocolString
예시
위치 프로토콜의 예를 살펴보겠습니다. 속성 -
<!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> 출력
이것은 다음과 같은 출력을 생성합니다 -
'프로토콜 받기'를 클릭하기 전에 버튼 -

'프로토콜 가져오기'를 클릭한 후 버튼 -
