亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

JavaScript編程中window的location與history對(duì)象詳解

 更新時(shí)間:2015年10月26日 16:58:09   投稿:goldensun  
這篇文章主要介紹了JavaScript編程中window的location與history對(duì)象,是JavaScript入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下

Window Location

  • window.location 對(duì)象用于獲得當(dāng)前頁(yè)面的地址 (URL),并把瀏覽器重定向到新的頁(yè)面。
  • window.location 對(duì)象在編寫時(shí)可不使用 window 這個(gè)前綴。 一些例子:
  • 一些實(shí)例:
  • location.hostname 返回 web 主機(jī)的域名
  • location.pathname 返回當(dāng)前頁(yè)面的路徑和文件名
  • location.port 返回 web 主機(jī)的端口 (80 或 443)
  • location.protocol 返回所使用的 web 協(xié)議(http:// 或 https://)

Window Location Href

location.href 屬性返回當(dāng)前頁(yè)面的 URL。
實(shí)例
返回(當(dāng)前頁(yè)面的)整個(gè) URL:

<script>

document.write(location.href);

</script>



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í)例
加載一個(gè)新的文檔:

<html>
<head>
<script>
function newDoc()
 {
 window.location.assign("http://www.w3cschool.cc")
 }
</script>
</head>
<body>

<input type="button" value="Load new document" onclick="newDoc()">

</body>
</html>


Window History
window.history對(duì)象在編寫時(shí)可不使用 window 這個(gè)前綴。
為了保護(hù)用戶隱私,對(duì) JavaScript 訪問該對(duì)象的方法做出了限制。
一些方法:

  • history.back() - 與在瀏覽器點(diǎn)擊后退按鈕相同
  • history.forward() - 與在瀏覽器中點(diǎn)擊按鈕向前相同

Window History Back

history.back() 方法加載歷史列表中的前一個(gè) URL。
這與在瀏覽器中點(diǎn)擊后退按鈕是相同的:
實(shí)例
在頁(yè)面上創(chuàng)建后退按鈕:

<html>
<head>
<script>
function goBack()
 {
 window.history.back()
 }
</script>
</head>
<body>

<input type="button" value="Back" onclick="goBack()">

</body>
</html>


Window History Forward
history forward() 方法加載歷史列表中的下一個(gè) URL。
這與在瀏覽器中點(diǎn)擊前進(jìn)按鈕是相同的:
實(shí)例
在頁(yè)面上創(chuàng)建一個(gè)向前的按鈕:

<html>
<head>
<script>
function goForward()
 {
 window.history.forward()
 }
</script>
</head>
<body>

<input type="button" value="Forward" onclick="goForward()">

</body>
</html>

相關(guān)文章

最新評(píng)論