JS 中document.URL 和 window.location.href 的区别
实际上,document 和 window 这两个对象的区别已经包含了这个问题的答案。
document 表示的是一个文档对象,window 表示一个窗口对象。
一个窗口下面可以有很多的document对象。每个document 都有 一个URL。
但是,这不是所有的区别。当你ctrl + F5 一个链接 http://yourhost.com/#fragment
打印 alert(document.URL ); 和 alert(window.location.href);
发现,这两个的值不一样,
document.URL 的值是 “http://yourhost.com/”
window.location.href 的值是 “http://yourhost.com/#fragment”
差一个 #fragment
所以,如果要用 fragment 进行相应的处理的话,最好是用 window.location.href
否则会出现很奇怪的错误。
另:以下是屏蔽页面使用查看源码和复制拷贝页面内容的js代码
document.oncontextmenu=function(e){return false;}
document.onmousedown = function() {
return false;
};
document.onselectstart = function() {
return false;
};
JS 中document.URL 和 window.location.href 的区别的更多相关文章
- JS 中document.URL 和 windows.location.href 的区别
实际上,document 和 windows 这两个对象的区别已经包含了这个问题的答案. document 表示的是一个文档对象,windows 表示一个窗口对象. 一个窗口下面可以有很多的docu ...
- document.URL vs window.location.href All In One
document.URL vs window.location.href All In One document.URL 与 window.location.href 两者有啥区别 document. ...
- document.URL 和 windows.location.href的区别
1. 从输出结果上,document.URL 和 windows.location.href 没有区别.2. 非要说区别的话,你只可以读取document.URL的值,不能修改它.windows.lo ...
- JS中document对象和window对象有什么区别
简单来说,document是window的一个对象属性.Window 对象表示浏览器中打开的窗口.如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 windo ...
- JS中 window.location 与window.location.href的区别
疑惑:window.location='url' 与window.lcoation.href='url'效果一样,都会跳转到新页面,区别在哪?查得的资料如下: 1:window.location是页 ...
- 【JavaScript】获取当前页的URL与window.location.href
原文:http://blog.csdn.net/yongh701/article/details/45688743 版权声明:本文为博主原创文章,未经博主允许欢迎乱转载,标好作者就可以了!感谢欣赏!觉 ...
- 页面的URL分析----window.location.href
window.location是页面的位置对象window.location.href是 location的一个属性值,并且它是location的默认属性. window.location直接赋值一个 ...
- javascript中window.open()与window.location.href的区别
window.open("www.baidu.com"); 只是表示打开这个页面,并不是打开并刷新baidu.com window.location.href="www. ...
- window.top.location.href 和 window.location.href 的区别
"window.location.href"."location.href"是本页面跳转. "parent.location.href" 是 ...
随机推荐
- 李洪强iOS开发之通知的使用
李洪强iOS开发之通知的使用 01 - 在A中发送通知 02 - 在B中监听通知 03 - 在B中通知出发的方法 04 - 在B控制器viewDidLoad调用通知
- jq的bind用法
type,[data],function(eventObject)String,Object,Function type: 含有一个或多个事件类型的字符串,由空格分隔多个事件.比如"clic ...
- 机器人学 —— 轨迹规划(Configuration Space)
之前的轨迹规划中,我们只考虑了质点,没有考虑机器人的外形与结构.直接在obstacle map 中进行轨迹规划,然而世纪情况中,机器人有固定外形,可能会和障碍物发生碰撞.此情况下,我们针对机器人自由度 ...
- highcharts联合jquery ajax 后端取数据
Highcharts是一个制作图表的纯Javascript类库,主要特性如下: 兼容性:兼容当今所有的浏览器,包括iPhone.IE和火狐等等: 对个人用户完全免费: 纯JS,无BS: 支持大部分的图 ...
- ActiveXObject Word.Application 打印小票
javascript 时间格式 Date.prototype.format = function (format) { var o = { "M+": this.getMonth( ...
- 压缩工具类 - ZipUtils.java
压缩工具类,提供压缩文件.解压文件的方法. 源码如下:(点击下载 - ZipUtils.java .FolderUtils.java.ant-1.7.0.jar.commons-io-2.4.jar. ...
- PHP读取Mongodb数据报错,Cannot natively represent the long 8331412483000 on this platform
在使用PHP进行读取Mongo数据时,如果读取的int数据过大时,会自动转变为int64位. 并会报以下错误: Cannot natively represent the long 833141248 ...
- ZOJ Problem Set - 3861 Valid Pattern Lock(dfs)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3861 这道题当时没做出来,后来经过队友提醒才做出来. 3*3的九宫格,给你 ...
- 总结Selenium自动化测试方法(五)自动化测试框架
五.自动化测试框架 1.单元测试框架unittest class loginTests(unittest.TestCase): ①开始的初始化部分 @classmethod def setUpClas ...
- 《OD大数据实战》HDFS入门实例
一.环境搭建 1. 下载安装配置 <OD大数据实战>Hadoop伪分布式环境搭建 2. Hadoop配置信息 1)${HADOOP_HOME}/libexec:存储hadoop的默认环境 ...