码迷,mamicode.com
首页 > 其他好文 > 详细

location 对象

时间:2015-05-21 12:36:56      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
// demo : "http://baidu.com/#contents"   返回URL中的hash (#号跟零或多个字符),如果URL中不包含散列,则返回空字符串
var a = window.location.hash;
// console.log(a); //#contents


// demo :"wwww.baidu.com:80"    返回服务器名称和端口号 (如果有)
var b = window.location.host;
console.log(b);


// demo : "www.baidu.com"   返回不带端口号的服务器名称
var c = window.location.hostname
console.log(x);


// demo : "http://www.baidu.com"    返回当前加载页面的完整URL。而location对象的toString()方法也返回这个值
var d = window.location.href;
console.log(d);


// demo : "/hehe/"  返回URL中的目录和(或)文件名
var e = window.location.pathname;
console.log(e);


// demo : "808"     返回URL中指定的端口号。如果URL中不包含端口号,则这个属性返回空字符串。
var f = window.location.port;
console.log(f);


// demo : "http:"   返回页面使用的协议。通常是 http: 或 https:
var g = window.location.protocol;
console.log(g);


// demo : "?s=javascript"   返回URL的查询字符串。这个字符串以问号开头
var h = window.location.search;
console.log(h);
</script>
</head>
<body>
    
</body>
</html>

 

location 对象

标签:

原文地址:http://www.cnblogs.com/baixc/p/4519199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!