我的代码怎么没有反应
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button onclick="openwindow()">创建窗口</button>
<button onclick="myFunction()">调整窗口</button>
<button onclick="moveFunction()">移动窗口</button>
<button onclick="closeFunction()">关闭窗口</button>
<script type="text/javascript">
var w;
function openwindow(){
//第一个参数:给一个链接,打开的窗口直接跳转转到该连接
//第二个参数:给这个窗口定义名字
//第三个参数:设定窗口的长宽
w=window,open('http://www.baidu.com','田氏企业','width=100,height=100');
}
function myFunction(){
w.resizeTo(500,500);//调整窗口,将w原本尺寸的窗口变为调整后的大小
w.focus();
}
function moveFunction(){
w.moveTo(700,500); //使w窗口移动到坐标为(700,500)的位置
w.focus;
}
function closeFunction(){
w.close;
w.focus;
}
// var a=1;
// alert( window.a) // 1 相当于a=window.a
</script>
</body>
</html>
正在回答
你好,涉及到调整窗口和移动窗口时,
1 2 | w=window.open(' http: //www.baidu.com','田氏企业','width=100,height=100'); |
不能天添加链接地址,加链接无法实现是因为跨页面操作涉及域的概念,
应该为:
w=window.open('','', 'width=300,height=300');
移动窗口:
1 2 3 4 | function moveFunction(){ w.moveTo(700,500); //使w窗口移动到坐标为(700,500)的位置 w.focus; } |
改为:
1 2 3 4 | function moveFunction(){ w.moveTo(700,500); //使w窗口移动到坐标为(700,500)的位置 w.focus(); } |
如果解决您的问题请采纳,祝学习愉快!
- 参与学习 人
- 提交作业 626 份
- 解答问题 4928 个
想要学好Web后端开发的中流砥柱语言,本阶段为你轻松铺就扎实的基础,从前端网页布局的搭建到后台PHP开发,助你从零基础到掌握主流开发语言。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧