JavaScript学习笔记——BOM_window对象

javascript浏览器对象模型-windwo对象

BOM Browser Object Model
window对象 是BOM中所有对象的核心。

一、属性

1.(位置类型-获得浏览器的位置)
  IE:
  window.screenLeft
  可以获得浏览器距屏幕左上角的左边距
  window.screenTop
  可以获得浏览器距屏幕左上角的上边距

//IE
   //左边距
   //alert(screenLeft)
   //上边距
   //alert(screenTop)

  FF:
  alert(screenX)
  alert(screenY)

//FF
  //左边距
  // alert(screenX)
  //上边距
  // alert(screenY)

  (获得浏览器的尺寸)

  FF:window.innerWidth 获得窗口的宽度
  window.innerHeight 获得窗口的高度

//获取浏览器的尺寸

    //FF:
      //alert(window.innerWidth);
      //alert(window.innerHeight);

    //IE和FF通用:
        alert(document.documentElement.clientWidth)
        alert(document.documentElement.clientHeight)        

2.关系类型

  A.parent返回父窗口
  B.top 返回顶层窗口

  C.self===window 相当于window

3.stutas 设置窗口状态栏的文本

    window.status="自定义的状态栏文字"


二、方法

1.窗体控制
  A.对窗体的移动

  window.moveBy(x,y) 相对于当前位置沿着XY轴移动指定的像素,如负数是反方向
  moveTo(x,y) 相对于浏览器的左上角沿着XY轴移动到指定的像素,如负数是反方向

     //位置
     moveBy(100,100);
      //moveTo(200,200)

  B.窗体尺寸的改变

  resizeBy(x,y) 相对于当前窗体的大小,调整宽度和高度
  resizeTo(x,y) 把窗体调整为指定宽度和高度

      //尺寸
       window.resizeBy(100,100)
       resizeTo(400,400)


2.对窗体滚动条的控制

  scrollBy(x,y) 相对于当前滚动条的位置移动的像素(前提有滚动条)
  scrollTo(x,y) 相对于当前窗口的高度或宽度,移动到指定的像素

     //scrollBy(0,100)
    //scrollTo(0,200)

3.时间间隔的函数

  setInterval("函数或者代码串",指定的时间(毫秒)) 按照指定的周期(毫秒)不断的执行函 数或是代码串

// setInterval("函数或者代码串",指定的时间(毫秒))  按照指定的周期(毫秒)不断的执行函  数或是代码串

//第一种调用方式
 // setInterval("alert('后盾网')",1000);
//  var i=0
// setInterval(changes,1000)
// function changes () {
//  alert(i)
//  i++
// }

//第二种调用方式
//var a=0;
//setInterval(function  () {
//  alert(a);
//  a++
//},1000)

//第三种调用方式
 //var i=0;
// setInterval("changes(0)",1000)
// function changes (i) {
//  alert(i)
//  i++
// }

  clearInterval()

//停止调用
 
  window.onload=function  () {
    var t=setInterval('alert("后盾网")',5000)
   var aa=document.getElementById("stop");
   aa.onclick=function  () {
    clearInterval(t)
   }
  }
  <input type="button" value="停止" id="stop">

  setTimeout("函数或者代码串",指定的时间(毫秒)) 在指定的毫秒数后只执行一次函数或代码。

  clearTimeout()

window.onload=function  () {
    var aa =setTimeout("alert('bbs.houdunwang.com')",5000)
   var bb=document.getElementById("stop");
   bb.onclick=function  () {
    clearTimeout(aa)
   }
  }

4.打开新的窗口

  open(url,name,feafurse,replace) 通过脚本打开新的窗口

    window.onload=function  () {
    var names=document.getElementById("names");
      var but=document.getElementById("but");
      but.onclick=function  () {
      open("26.1.html","windows","status=0,menubar=0,toolbar=0")
      }

    }






原文地址:https://www.cnblogs.com/tonglin0325/p/4713925.html