实际上,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. stringbuffer与stringbuilder的区别?

    1. 在执行速度方面的比较:StringBuilder > StringBuffer 2. StringBuffer与StringBuilder,他们是字符串变量,是可改变的对象,每当我们用它们 ...

  2. YTU 2614: A代码完善--系统日期

    2614: A代码完善--系统日期 时间限制: 1 Sec  内存限制: 128 MB 提交: 216  解决: 113 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 已知某操作 ...

  3. Javascript上下文

    var User = { count: 1, getCount: function() { return this.count; } }; console.log(User.getCount()); ...

  4. mvp(1)简介及它与mvc区别

    注意:它们是软件架构,不是设计模式 左边mvc    右边mvp MVC和MVP的区别? MVP 是从经典的MVC架构演变而来,它们的基本思想有相通的地方:Controller/Presenter负责 ...

  5. How to: Synchronize Files by Using Managed Code

    The examples in this topic focus on the following Sync Framework types: FileSyncProvider FileSyncOpt ...

  6. leetcode:Reverse Linked List

    Reverse a singly linked list. 代码如下: the iterative solution:(c++) /** * Definition for singly-linked ...

  7. oracle数据导入的常用命令

    oracle 中数据库完全导入导出:cmd命令行模式 oracle数据库cmdfile数据库服务器constraints Oracle数据导入导出imp/exp就相当于oracle数据还原与备份.ex ...

  8. 一个发光的搜索边框(纯CSS3)

    这是效果图,边框会不停的闪,兼容各种浏览器 HTML代码: <body> <div class="container"> <form method=& ...

  9. JQuery操作Ajax

    一.jQuery - AJAX 简介 AJAX = 异步 JavaScript 和 XML(Asynchronous JavaScript and XML). AJAX 是与服务器交换数据的艺术,它在 ...

  10. mysql数据库导入外键约束问题

    在网站搬迁过程中,很重要一点是数据的迁移.你的数据库可能已经包含了一个设计良好的数据表集合,并且在网站运营过程中,产生了重要的数据.这时你必须做好包含数据表schema以及数据本身的迁移. 完成上述数 ...