location 位置

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<button type="button" onclick="newDoc()">加载新文档</button>
<br />
<body>
<script>
document.write('输出当前位置的路径:');
document.write(location.href);
document.write('</br>');
document.write('输出当前位置的端口:');
document.write(location.port);
document.write('</br>');
document.write('输出当前位置的协议:');
document.write(location.protocol);
document.write('</br>');
document.write('输出web主机的域名:');
document.write(location.hostname);
document.write('</br>');
document.write('返回单前页面的路径和文件名:');
document.write(location.pathname);
document.write('</br>');
function newDoc(){
document.location.assign('http://www.zhaocom.xyz');
}
</script>
</body>
</html>

posted @ 2018-04-08 09:21  赵翔个人博客  阅读(104)  评论(0编辑  收藏  举报