zoukankan      html  css  js  c++  java
  • JS 中document.URL 和 windows.location.href 的区别

    实际上,document 和 windows 这两个对象的区别已经包含了这个问题的答案。

     
    document 表示的是一个文档对象,windows 表示一个窗口对象。 
    一个窗口下面可以有很多的document对象。每个document 都有 一个URL。 

    但是,这不是所有的区别。当你ctrl + F5 一个链接 http://www.jbxue.com/#server 
    打印 alert(document.URL ); 和 alert(windows.location.href); 
    发现,这两个的值不一样, 
    document.URL : http://www.jbxue.com/ 
    windows.location.href :http://www.jbxue.com/#server 

    所以,如果要用 fragment 进行相应的处理的话,最好是用 windows.location.href,否则会出现很奇怪的错误。
  • 相关阅读:
    [TCP/IP]TCP的三次握手和四次挥手

    思考
    jQuery完整的事件委托(on())
    jQuery队列动画
    jQuery自定义动画
    jQuery淡入淡出
    jQuery滑动动画
    jQuery基本动画
    jQuery基础3
  • 原文地址:https://www.cnblogs.com/cfinder010/p/3354934.html
Copyright © 2011-2022 走看看