1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 5 <title>location对象</title> 6 <script> 7 var str = "<h2>当前地址的相关信息如下</h2>"; 8 str += "完整的URL地址:"+location.href; 9 alert(location.href); 10 str += "<br>协议:"+location.protocol; 11 str += "<br>主机名:"+(location.host ? location.host :"主机不存在"); 12 str += "<br>文件名:"+location.pathname; 13 str += "<br>查询字符串:"+location.search ? location.search :"查询的字符串不存在"; 14 str += "<br>锚点:"+location.hash; 15 document.write(str+"<hr>"); 16 17 </script> 18 </head> 19 <body> 20 <input type="button" value="刷新网页" onclick="location.reload()" /> 21 22 <a href="javascript:void(0)" onclick="history.go(-1)">进入上一页</a> 23 </body> 24 </html>