欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
location中assign,protocol的使用方法
 
window.location.protocol 返回使用的 web 协议(http: 或 https:)
 
window.location.assign 加载新文档
 
Window Location 协议
 
window.location.protocol 属性返回页面的 web 协议。
 
实例
 
显示 web 协议:
 
document.getElementById("demo")。innerHTML = "页面协议是 " + window.location.protocol;
 
结果是:
 
页面协议是 http:
 
Window Location 端口
 
window.location.port 属性返回(当前页面的)互联网主机端口的编号。
 
实例
 
显示主机的端口号:
 
document.getElementById("demo")。innerHTML = "端口号是: " + window.location.port;
 
大多数浏览器不会显示默认端口号(http 为 80,https 为 443)。
 
Window Location Assign
 
window.location.assign() 方法加载新文档。
 
实例
 
加载新文档:
 
<html>
 
<head>
 
<script>
 
function newDoc() {
 
    window.location.assign("https://www.w3school.com.cn")
 
 }
 
</script>
 
</head>
 
<body>
 
<input type="button" value="Load new document" onclick="newDoc()">
 
</body>
 
</html> 

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h64515.shtml