10
09/2014
javascript window 相关
访问 window.open 窗口
<a class="btn" href="javascript:void(0);" onclick="var win=window.open('/','testWin','left=0,top=0,width=300,height=300');win.moveTo(0,0);win.moveBy(100,100);win.document.write('你好!我来了');var s=win.opener.document.title;win.document.title='父窗口标题:'+s;win.alert('走!');win.resizeTo(500,200);win.moveTo(screen.availWidth-500,screen.availHeight-200);div=win.document.createElement('div');div.innerHTML='<p style=\'color:blue\'>我到达了右下角<p>';win.document.body.insertBefore(div);win.alert('回!');win.moveTo(screen.availWidth-500,0);win.document.body.innerHTML=('<h1 style=\'color:red\'>再见!</h1>');setTimeout(function(){win.close()},1000)">window open 例子</a>
被打开窗口访问父窗口,使用 window.opener。
screen 属性
var sSTr=''; for(prop in screen) { sSTr+=prop+': '+screen[prop]+'\n'; } alert(sSTr);
scrollIntoView(alignWithTop)
alignWithTop true 向上对齐;false 向下对齐
scrollIntoView(true) scrollIntoView(false)
window 控制
- win.moveBy(x,y)
- win.moveTo(x,y)
- win.resizeBy(width,height)
- win.resizeTo(width,height)
- win.scrollBy(x,y)
- win.scrollTo(x,y)