Location origin 속성은 URL의 프로토콜, 호스트 이름, 호스트 포트 번호(지정된 경우)에 해당하는 문자열을 반환합니다.
구문
다음은 구문입니다 -
원본의 반환 값 재산
location.origin
예시
위치 출발지의 예를 살펴보겠습니다. 속성 -
<!DOCTYPE html>
<html>
<head>
<title>Location origin</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-origin</legend>
<label for="urlSelect">Current URL:</label>
<input type="url" size="30" id="urlSelect" value="https://www.example.com:2544/aboutUs">
<input type="button" onclick="getorigin()" value="Get origin">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var urlSelect = document.getElementById("urlSelect");
function getorigin(){
divDisplay.textContent = 'URL Origin: '+location.origin;
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -
'원본 가져오기'를 클릭하기 전에 버튼 -

'원본 가져오기'를 클릭한 후 버튼 -
