zoukankan      html  css  js  c++  java
  • javascript -window与document 待整理

    window对象和document对象的区别
    一般来讲,一个window里就是一个document,但是,iframe里面也可以装个document,在iframe里面就有区别了

    alert(document.location === window.location); // true

    不要混淆Window对象的location属性和Document对象的location属性。前者引用一个Location对象,而后者只是一个只
    读字符串,并不具有Location对象的任何特性。document.location与document.URL是同义的,后者在
    JavaScript1.1中是该属性的首选名称(因为这样避免了潜在的混淆)。在大多数情况下,document.location和
    location.href是相同的。但是,当存在服务器重定向时,document.location包含的是已经装载的URL,而
    location.href包含的则是原始请求的文档的URL。

    document.location和window.location有什么区别就是
    document你可以理解为文档,就是你的网页
    window理解为窗口,就是你的ie浏览器包含的
    无框架:简单的说,没有框架的情况下,是等同的
    有框架:在有框架的情况下,最外层是相同的,在iframe里面的document.location和window.location不同的。
    iframe里面的document.location 你看不ie地址变化,只改变iframe部分,
    此时的window.location和top.location效果一致

    document.location="url";(只读)
    document.location.reload("url";);
    window.location="url";
    location="url";
    document.href="url"
    document.location.href="url"
    document.location.replace="url"
    document.action="url"; document.submit();
    document.location.href和document.location.replace都可以实现从A页面切换到B页面,但他们的区别是:
    用document.location.href切换后,可以退回到原页面。而用document.location.replace切换后,不可以通过“后退”退回到原页面。
    关于document.location.href或其他可回退的切换方式
    document.location 相当于 document.URL 声明了装载文档的URL,
    除非发生了服务器重定向, 否则该属性的值与Window.location.href的值是一样的.
    history.go(-1);//返回上一页
    document.IFRAME名称.location.href='url';//改变框架内容 
           

    一步一个脚印,方便自己复习,该出手时就出手,有错误,一定要指正,非常感谢,共同进步!
  • 相关阅读:
    第六课 使用oflash软件烧写bin文件至开发板
    Linux查看、添加、修改PATH环境变量
    第七课 Linux裸机开发+SourceInsight3.5使用+notepad++使用
    第五课 Linux高级命令
    数组的方法总结
    浅谈 return false 和preventDefault stopPropagation stopImmediatePropagation 的正确用法
    实时统计输入的文字
    滚轮滚动事件
    window.onload和DOMReady
    JS获取浏览器可视区域的尺寸
  • 原文地址:https://www.cnblogs.com/keyi/p/6137483.html
Copyright © 2011-2022 走看看