首页 > 应用开发 > IT综合 > 细说JavaScript BOM
| 方法 | 描述 |
| alert() | 弹出带有文本消息和一个确认按钮的警告框 |
| prompt() | 弹出可提示用户输入的对话框 |
| confirm() | 弹出带有文本消息及确认按钮和取消按钮的对话框 |
| open() | 打开一个新的浏览器窗口 |
| close() | 关闭浏览器窗口 |
| print() | 打印当前窗口的内容 |
| focus() | 把键盘焦点给予一个窗口 |
| blur() | 把键盘焦点从顶层窗口移开 |
| moveBy(xnum, ynum) | 相对窗口的当前坐标将对象移动指定的像素 |
| moveTo(x, y) | 把窗口的左上角移动到一个指定的坐标 |
| resizeBy(w, h) | 按照指定的像素调整窗口的大小 |
| resizeTo(w, h) | 将窗口的大小调整到指定的宽度和高度 |
| scrollBy(xnum, ynum) | 按照指定的像素值来滚动内容 |
| scrollTo(x, y) | 将内容滚动到指定的坐标 |
| setInterval() | 每隔指定的时间执行代码 |
| setTimeout() | 在指定的延迟时间之后来执行代码 |
| clearInterval() | 取消 setInterval() 的设置 |
| clearTimeout() | 取消 setTimeout() 的设置 |
|
参数
|
值
|
说明
|
|
top
|
Num
|
新窗口距屏幕顶部的距离
|
|
left
|
Num
|
新窗口距屏幕左端的距离
|
|
width
|
Num
|
新窗口的宽度
|
|
height
|
Num
|
新窗口的高度
|
|
menubar
|
yes/no/1/0
|
窗口是否有菜单栏,默认是yes
|
|
scrollbars
|
yes/no/1/0
|
窗口是否有滚动条,默认是yes
|
|
toolbar
|
yes/no/1/0
|
窗口是否有工具栏,默认是yes
|
|
status
|
yes/no/1/0
|
窗口是否有状态栏,默认是yes
|
|
location
|
yes/no/1/0
|
窗口是否显示地址栏,默认是yes
|
|
resizable
|
yes/no/1/0
|
是否允许改变窗口大小,默认是yes
|
|
directories
|
yes/no/1/0
|
是否添加目录按钮,默认是yes
|
|
|
<body>
<input type="button" value="点击我,打开新窗口!">
<script>
function newWin(){
window.open('http://www.shsxt.com/', '_blank', 'width=600,height=400,top=0,left=10');
}
script>
body>
|
|
|
|
|
<body>
<input type="button" value="获得焦点">
<script>
//确保新的窗口获得焦点:
function openWin(){
var oGet = window.open('', '', 'width=400,height=400');
oGet.document.write('<p>我是新打开的窗口p>');
oGet.focus();
}
script>
<input type="button" value="失去焦点">
<script>
//确保新的窗口没有获得焦点:
function newWin(){
var lose = window.open('', '', 'width=400,height=300');
lose.document.write('<p>我是新打开的窗口p>');
lose.blur();
}
script>[/font][/color][/align]
[align=left][font=black Verdana, Arial, Helvetica, sans-serif][color=#000000]body>
|
|
|
<body>
<input type="button" value="打开">
<script>
function openWin(){
var newWin = window.open('', 'newWindow', 'width=400,height=300');
newWin.document.write('<p>新窗口名称:' + newWin.name + 'p>');
}
script>
body>
|
|
|
<body>
<input type="button" value="打开">
<script>
function openWin(){
var newWin = window.open('', '', 'width=400,height=300');
newWin.document.write('<p>关闭我之后会向父窗口输入文本信息p>');
newWin.focus();
newWin.opener.document.write('<p>我是父窗口,加载完成后,向我输出内容会覆盖我所有内容p>');
}
script>
body>
|
|
|
<html>
<head>
<meta charset="UTF-8">
<title>JavaScript实例title>
head>
<body>
<br><br>
<h4>用指定像素调整窗口大小:h4>
<input type="button" value="打开"><br><br>
<input type="button" value="调整">
<script>
var w;
function openWin(){
w=window.open('', '', 'width=100,height=100,top=10');
w.focus();
}
function byWin(){
//如果不使用框架,可使用window代替top
w.top.resizeBy(500,500);
w.focus();
}
script>
<h4>将窗口的大小调整到指定的宽度和高度:h4>
<input type="button" value="打开"><br><br>
<input type="button" value="调整">
<script>
var w;
function newWin(){
w=window.open('', '', 'width=100,height=100');
w.focus();
}
function toWin(){
w.resizeTo(500,500);
w.focus();
}
script>
<h4>相对于当前位置移动新窗口:h4>
<input type="button" value="打开"><br><br>
<input type="button" value="多移动几下">
<script>
var w;
function oWin(){
w = window.open('', '', 'width=100,height=100');
}
function moveWin(){
w.moveBy(200,200);
w.focus();
}
script>
<h4>移动新窗口到指定位置:h4>
<input type="button" value="打开"><br><br>
<input type="button" value="移动">
<script>
var w;
function nWin(){
w=window.open('', '', 'width=400,height=300');
}
function moveToWin(){
w.moveTo(0,0);
w.focus();
}
script>
<h4>由指定的像素数滚动内容:h4>
<input type="button" style="position:fixed;top:0;" value="由指定的像素数滚动内容">
<script>
function scrollWin(){
window.scrollBy(10,10);
}
script>
<h4>滚动到指定内容处:h4>
<input type="button" value="滚动到指定内容处">
<script>
function scrollWindow(){
window.scrollTo(10,50);
}
script>
<br><br><br><br><br><br>
body>
html>
|
|
|
//点击按钮关闭当前窗口
<input type="button" value="关闭窗口">
|
|
|
//先用open打开保存的文档,然后再点击关闭窗口按钮,效果就达到了
<input type="button" value="打开窗口">
|
|
|
<a href="javascript:window.opener=null;window.open('', '_self');window.close();">关闭a>
|
|
|
<body>
<input type="button" value="打开">
<input type="button" value="关闭">
<script>
function openWin(){
newWin = window.open('http://www.shsxt.com/', '', 'width=400,height=300,top=200');
}
function closeWin(){
newWin.close();
}
script>
body>
|
|
|
<body>
<input type="button" value="打开'">
<input type="button" value="关闭">
<input type="button" value="是否关闭">
<p id="p1">p>
<script>
var newWin;
function openWin(){
newWin = window.open('', '', 'width=400,height=300,top=200');
}
function closeWin(){
if(newWin){
newWin.close();
}
}
var oP = document.getElementById('p1');
function checkWin(){
if(!newWin){
oP.innerHTML = '新窗口还没被打开!';
}
else{
if(newWin.closed){
oP.innerHTML = '新窗口已关闭!';
}
else{
oP.innerHTML = '新窗口未关闭!';
}
}
}
script>
body>
|
|
|
<body>[/font][/color][/align][align=left][color=rgb(0, 0, 0)][font="]
<div id="div1">div>
<script>
txt = '<p>Browser CodeName(浏览器代码名称): ' + navigator.appCodeName + 'p>';
txt+= '<p>Browser Name(浏览器名称): ' + navigator.appName + 'p>';
txt+= '<p>Browser Version(浏览器版本): ' + navigator.appVersion + 'p>';
txt+= '<p>Cookies Enabled(启用Cookies): ' + navigator.cookieEnabled + 'p>';
txt+= '<p>Platform(操作平台): ' + navigator.platform + 'p>';
txt+= '<p>User-agent header(由客户机发送服务器的 user-agent 头部信息): ' + navigator.userAgent + 'p>';
txt+= '<p>User-agent language(客户机代理语言): ' + navigator.systemLanguage + 'p>';
document.getElementById('div1').innerHTML=txt;
script>
body>
|
|
|
<script>
document.write(navigator.userAgent);
script>
|
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31494694/viewspace-2147754/ ,如需转载,请注明出处,否则将追究法律责任。