宿主对象

Window 对象方法
Window 对象表示浏览器中打开的窗口

  • alert() 方法用于显示带有一条指定消息和一个 OK 按钮的警告框。
var arr = "hello world";
alert(arr);
  • blur() 方法可把键盘焦点从顶层窗口移开。
myWindow=window.open('','','width=200,height=100')
myWindow.document.write("This is 'myWindow'")
myWindow.blur()
  • clearInterval() 方法可取消由 setInterval() 设置的 timeout。
var timer = setInterval(function(){
    var t = new Date();
    t = document.getElementById('clock').value;
},500);
oBox.onmousemove = function(){
    clearInterval(timer);
}
  • clearTimeout() 方法可取消由 setTimeout() 方法设置的 timeout。
<script type="text/javascript">
var c=0;
var timer;
function timedCount(){
  c=document.getElementById('txt').value;
  c=c+1;
  timer=setTimeout("timedCount()",1000);
 }
function stopCount(){
  clearTimeout(timer);
 }
</script>

<form>
<input type="button" value="Start count!" onClick="timedCount()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onClick="stopCount()">
</form>
  • close() 方法用于关闭浏览器窗口。
<script type="text/javascript">
function closeWin(){
  myWindow.close()
}

myWindow=window.open('','','width=200,height=100')
myWindow.document.write("This is 'myWindow'")
</script>

<input type="button" value="Close 'myWindow'"
onclick="closeWin()" />
  • confirm() 方法用于显示一个带有指定消息和 OK 及取消按钮的对话框。
var str = "hello world!";
confirm(str);
  • focus() 方法可把键盘焦点给予一个窗口。
myWindow=window.open('','','width=200,height=100')
myWindow.document.write("This is 'myWindow'")
myWindow.focus()
  • moveBy() 方法可相对窗口的当前坐标把它移动指定的像素。
window.moveBy(100,80)//把窗口右移100个像素,下移80个像素
  • moveTo() 方法可把窗口的左上角移动到一个指定的坐标。
window.moveTo(200,150)//把窗口移动到坐标为(200,100)的位置
  • open() 方法用于打开一个新的浏览器窗口或查找一个已命名的窗口。
window.open("index.html")//在新窗口打开
  • prompt() 方法用于显示可提示用户进行输入的对话框。
 function disp_prompt(){
  var name=prompt("请输入您的名字","Bill Gates");
  if (name!=null && name!=""){
    document.write("你好," + name + "!今天过得好吗?");
  }
 }
<input type="button" onclick="disp_prompt()"value="显示一个提示框" />

Location 对象方法
Location 对象是 Window 对象的一个部分,可通过 window.location 属性来访问。

  • assign() 方法可加载一个新的文档。
function newDoc(){                                  window.location.assign("http://www.w3school.com.cn")
}

<input type="button" value="Load new document" onclick="newDoc()" />
  • reload() 方法用于重新加载当前文档。
function reloadPage(){
  window.location.reload()
}

<input type="button" value="Reload page"
onclick="reloadPage()" />
  • replace() 方法可用一个新文档取代当前文档。
function replaceDoc(){
    window.location.replace("http://www.blog.csdn.net")
}
<input type="button" value="Replace document" onclick="replaceDoc()" />

Screen 对象的方法

  • availHeight 属性声明了显示浏览器的屏幕的可用高度,以像素计。(除 Windows 任务栏之外)
document.write(screen.availHeight);
  • availWidth 属性声明了显示浏览器的屏幕的可用宽度,以像素计。(除 Windows 任务栏之外)
document.write(screen.availWidth)
  • height 属性声明了显示浏览器的屏幕的高度,以像素计。
document.write(screen.height)
  • width 属性声明了显示浏览器的屏幕的宽度,以像素计。
document.write(screen.width)

History 对象的方法

  • back() 方法可加载历史列表中的前一个 URL(如果存在)。
function goBack(){
  window.history.back()
}
<input type="button" value="Back" onclick="goBack()" />
  • forward() 方法可加载历史列表中的下一个 URL。调用该方法的效果等价于点击前进按钮或调用 history.go(1)。
function goForward(){
  window.history.forward()
}

<input type="button" value="Forward" onclick="goForward()" />
  • go() 方法可加载历史列表中的某个具体的页面。
function goBack(){
  window.history.go(-1)//加载前一个页面
}
<input type="button" value="Back" onclick="goBack()" />
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值