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]iPhone推送原理
推送原理,先上图 说一下原理吧, 由App向iOS设备发送一个注册通知 iOS向APNs远程推送服务器发送App的Bundle Id和设备的UDID APNs根据设备的UDID和App的Bundle ...
- mfc Clistctr 单元格嵌入图片(bmp)
示例:http://download.csdn.net/detail/zahxz/4652543 代码: CListCtrl mCtrlist;//列表控件 CImageList m_ImageLis ...
- ThreadLocal,ThreadLocalMap,Thread 的相互关系
1.ThreadLocal. 真正关键的类是它的内部类ThreadLocalMap,ThreadLocal 基本上相当于一个代理,或者算是Facade模式的应用,还没想清楚这种设计的妙处.(经过分析, ...
- 可视化MNIST之降维探索Visualizing MNIST: An Exploration of Dimensionality Reduction
At some fundamental level, no one understands machine learning. It isn’t a matter of things being to ...
- USACO Section 3.2: Sweet Butter
这题我自己是用邻接矩阵+dijskstra方法来求的,第九个例子TLE.网上看了别人的代码,是用邻接表+BFS来完成. 这里可以学到两个小技巧,邻接表的表示方法和INT_MAX的表示方法. /* ID ...
- c# 计算1-100之间的所有质数(素数)的和
求1-100之间的所有质数(素数)的和: 所以先必须知道什么是质数? 一个数是不是素数 “素数”是指除了能被1和自身整除外,不能被任何其它整数整除的自然数. 然后知道有哪些是质数: 记忆的方法: ...
- linux c 生成uuid
/********方法一**********/#include <stdio.h> #include <stdlib.h> #include <string.h> ...
- 关于Linux系统调用,内核函数【转】
转自:http://blog.csdn.net/ubuntulover/article/details/5988220 早上听人说到某个程序的一部分是内核态,另一部分是用户态,需要怎么怎么.当时突然想 ...
- jQuery 清除div内容
$.ajax({ url: "SearchSN.aspx", data: "SN=" + $("#txtS ...
- poj 1159 (DP LCS)
滚动数组 + LCS // File Name: 1159.cpp // Author: Missa_Chen // Created Time: 2013年07月08日 星期一 10时07分13秒 # ...