HTML DOM Location origin 属性
Location origin 属性返回对应于 URL 的协议、主机名、主机端口号(如果已指定)的字符串。
语法
以下是语法 −
返回 origin 属性的值
location.origin
示例
我们来看看 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>输出
将产生以下输出 −
单击 ‘获取 origin’ 按钮之前 −

单击 ‘获取 origin’ 按钮之后 −

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