国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

JavaScript Window Location


window.location 對(duì)象用于獲得當(dāng)前頁面的地址 (URL),并把瀏覽器重定向到新的頁面。


Window Location

window.location 對(duì)象在編寫時(shí)可不使用 window 這個(gè)前綴。 一些例子:

一些實(shí)例:

  • location.hostname 返回 web 主機(jī)的域名

  • location.pathname 返回當(dāng)前頁面的路徑和文件名

  • location.port 返回 web 主機(jī)的端口 (80 或 443)

  • location.protocol 返回所使用的 web 協(xié)議(http:// 或 https://)


Window Location Href

location.href 屬性返回當(dāng)前頁面的 URL。

實(shí)例

返回(當(dāng)前頁面的)整個(gè) URL:

<script>

document.write(location.href);

</script>

以上代碼輸出為:

http://miracleart.cn/js/js-window-location.html



Window Location Pathname

location.pathname 屬性返回 URL 的路徑名。

實(shí)例

返回當(dāng)前 URL 的路徑名:

<script>

document.write(location.pathname);

</script>

以上代碼輸出為:

/js/js-window-location.html



Window Location Assign

location.assign() 方法加載新的文檔。

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)(php.cn)</title>
</head>
<head>
<script>
function newDoc(){
	window.location.assign("http://miracleart.cn")
}
</script>
</head>
<body>

<input type="button" value="加載新文檔" onclick="newDoc()">

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例