1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>location对象</title>
6
7 <script type="text/javascript">
8 /*location对象*/
9 //location对象是最有用的BOM对象之一,它提供了与当前窗口加载的文档有关信息,还提供了一些导航功能
10 //事实上,location对象是一个很特别的对象,因为他既有window对象的属性,也是document对象
11 //的属性;换句话说,window.location和document.location引用的是同一个对象。
12 //host,href,pathname,port,protocol,search
13 //例1:查询
14 //导航功能:location.href="https://www.baidu.com"
15 //location.hash="#section1";
16 // location.search="?q=javascript"
17 //location.hostname="www.yahoo.com"
18 //location.pathname="mydir"
19 //location.port=8080;
20 location.replace("http://www.baidu.com");
21 location.href="http://www.sina.com.cn/"//place和href有一个区别就是href会惨胜浏览记录,replace不会。
22 </script>
23 </head>
24 <body>
25
26 </body>
27 </html>