实际上,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 的区别的更多相关文章

  1. JS 中document.URL 和 windows.location.href 的区别

    实际上,document 和 windows 这两个对象的区别已经包含了这个问题的答案. document 表示的是一个文档对象,windows 表示一个窗口对象.  一个窗口下面可以有很多的docu ...

  2. document.URL vs window.location.href All In One

    document.URL vs window.location.href All In One document.URL 与 window.location.href 两者有啥区别 document. ...

  3. document.URL 和 windows.location.href的区别

    1. 从输出结果上,document.URL 和 windows.location.href 没有区别.2. 非要说区别的话,你只可以读取document.URL的值,不能修改它.windows.lo ...

  4. JS中document对象和window对象有什么区别

    简单来说,document是window的一个对象属性.Window 对象表示浏览器中打开的窗口.如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 windo ...

  5. JS中 window.location 与window.location.href的区别

    疑惑:window.location='url'  与window.lcoation.href='url'效果一样,都会跳转到新页面,区别在哪?查得的资料如下: 1:window.location是页 ...

  6. 【JavaScript】获取当前页的URL与window.location.href

    原文:http://blog.csdn.net/yongh701/article/details/45688743 版权声明:本文为博主原创文章,未经博主允许欢迎乱转载,标好作者就可以了!感谢欣赏!觉 ...

  7. 页面的URL分析----window.location.href

    window.location是页面的位置对象window.location.href是 location的一个属性值,并且它是location的默认属性. window.location直接赋值一个 ...

  8. javascript中window.open()与window.location.href的区别

    window.open("www.baidu.com"); 只是表示打开这个页面,并不是打开并刷新baidu.com window.location.href="www. ...

  9. window.top.location.href 和 window.location.href 的区别

    "window.location.href"."location.href"是本页面跳转. "parent.location.href" 是 ...

随机推荐

  1. ./jad: error while loading shared libraries: libstdc++-libc6.2-2.so.3: cannot open shared object file: No such file or directory

    Ubuntu 上使用jad,出现上面错误: ./jad: error while loading shared libraries: libstdc++-libc6.2-2.so.3: cannot ...

  2. 复习一下,? extends T 和 ? super T

    前话 最近学一些杂七杂八的东西,都把基础给忘了. 比如Java泛型中的 ? extends T和 ? super T 吧. 刚看开源项目的时候遇到它,表情如下: 源码分析 直接用源码来讲解吧 pack ...

  3. photoshop:css3插件

    CSS3PS是Photoshop 插件,用来将 PhotoShop 的图层如内阴影.内发光.阴影.外发光.图片圆角等效果转成用 CSS3 样式. 官方下载地址>> http://css3p ...

  4. 【重走Android之路】【Java面向对象基础(二)】细说String、StringBuffer和StringBuilder

    [重走Android之路][基础篇(二)][Java面向对象基础]细说String.StringBuffer和StringBuilder   1.String String是Java中的一个final ...

  5. Windows环境变量设置无效解决办法——DOS窗口设置环境变量

    公司配置的电脑是Win7,使用的账户并不是管理员账户,我在计算机->属性中设置环境变量无效. 后来在DOS窗口中设置环境变量成功. 1. set [环境变量名称]=[所有环境变量值]:set P ...

  6. android sqlite 怎么写入存储时间

    字符串类型2013-12-10 12:12:12 SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd"); ...

  7. 整合Struts2+SiteMesh+Spring+MyFaces(JSF)+Freemarker的时候启动服务器报错ClassNotFoundException: org.apache.struts2.sitemesh.FreeMarkerPageFilter

    我一琢磨,难道freemarker与struts2的整合也需要添加一个struts2-freemarker-plugin的jar包? 后来找了半天,确认不需要这个. 然后我就上网搜,这个FreeMar ...

  8. ubuntu启动eclipse时出错cannot open display

    由于要学习hadoop,就在ubuntu下创建了一个hadoop用户,但是eclipse是在naomi用户下装的,在root和naomi用户下都能正常启动,但是一旦切换到hadoop用户,试着启动ec ...

  9. HTTP 请求方式: GET和POST的比较

    GET和POST是HTTP的两个常用方法.   什么是HTTP? 超文本传输协议(HyperText Transfer Protocol -- HTTP)是一个设计来使客户端和服务器顺利进行通讯的协议 ...

  10. hdu4760Good Firewall

    4760 数组模拟就可以了 读的时候可以整数读入 #include <iostream> #include<cstdio> #include<cstring> #i ...