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" 是 ...
随机推荐
- const以及入栈出栈
#include "stdafx.h"#include <iostream>using namespace std; class StringStack{ enum{s ...
- vim不保存退出
对于刚开始使用vi/vim文本编辑器的新手来说,如何在不保存更改而退出vi/vim 文本编辑器呢? 当你使用linux vi/vim 文本编辑器对linux下某个配置文件做编辑操作,当你更改完之后,可 ...
- MongoDB的SSL实现分析
1. OPENSSL接口封装 MongoDB封装了OPENSSL的SSL通信接口,代码在mongo/util/net目录.主要包括以下几个方面: 1) SSL配置参数,在ssl_options(.cp ...
- rc.local自启动学习(转)
linux有自己一套完整的启动体系,抓住了linux启动的脉络,linux的启动过程将不再神秘. 本文中假设inittab中设置的init tree为: /etc/rc.d/rc0.d/etc/rc. ...
- hdu1005 Number Sequence(数论)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- git服务器gitlab之搭建和使用--灰常好的git服务器【转】
转自:http://blog.csdn.net/zy416548283/article/details/38057925 git服务器比较有名的是gitosis和gitolite,这两个管理和使用起来 ...
- Html 修改placeholder的颜色属性css样式
项目需求需要修改文本框的placeholder 的文本颜色, 百度下, 备忘,我使用的是这种方法, ::-webkit-input-placeholder { /* WebKit browsers * ...
- 第六篇 ORACLE EBS用户界面通用元素或功能背后的道理解析
本篇打算介绍一下ORACLE EBS用户界面(User Interface)中通用的元素或功能背后蕴含的一些道理.这些通用元素或功能包括: List of Values (LOV),值列表 Flexf ...
- Order to Cash Process
order to cash process steps can be listed as below · Enter the Sales Order · Book the Sales Order · ...
- 一、导入、导出远程Oracle数据库
一.导入.导出远程Oracle数据库 其语法实示例如下: imp/exp [username[/password[@service]]] 其中service是服务实例名,关于如何创建服务实 ...