JavaScript -- 练习 window 流氓广告
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>无标题文档</title> <script type="text/javascript"> function test1() { var name = window.navigator.appName; var version = window.navigator.appVersion; var url = window.location.href; //alert(name + "___" + version + "___" + url); var cf = window.confirm("给出你的选择"); //确认提示框 if(cf == true) alert(cf); /*for(var i=0; i<500; i++ ) //窗体震动 { window.moveBy(50,0); window.moveBy(0,50); window.moveBy(-50,0); window.moveBy(0,-50); }*/ var text = window.prompt("提示信息:请输入一个值", "默认值: hello"); //输入信息 //alert(text); } var iTimerID = ""; function test2() //弹流氓广告 { var oNewWindow = window.open("1.html", "_blank", "location=no, menubar=no, scrollbars=no, status=no, titlebar=no, toolbar=no"); //oNewWindow.setTimeout("window.close()", "3000"); 三秒后关闭 //每三秒来一个 //iTimerID = window.setInterval("window.open('1.html', 'blank', 'location=no, menubar=no, scrollbars=no, status=no, titlebar=no, toolbar=no')",3000); } window.onload = function() //浏览器加载完成后就自动弹广告 { test2(); } window.onbeforeunload = function() //要关,点X就弹广告 { test2(); } window.onunload = function() //关闭还弹广告 { test2(); } window.onfocus = function() //获取焦点 { //alert("获得了焦点"); } function test3() { clearInterval(iTimerID); } function func_key() { if( window.event.keyCode<=48 || window.event.keyCode>=57) { var node = event.srcElement; // 获得事件触发源 alert(node.nodeName + "___" + node.nodeType + "___" + node.type); alert("只能输入数字"); event.returnValue = false; } } </script> </head> <body> <input type="button" name="bt1" value="点击" onclick="test1()" /> <br /> <input type="button" name="bt2" value="流氓广告" onclick="test2()" /> <br /> <input type="button" name="bt3" value="停止弹流氓广告" onclick="test3()" /> <br /> <input type="text" name="text1" onkeypress="func_key()" /> <br /> </body> </html>
流氓广告内容
<html> <head> <title>流氓广告</title> </head> <body> <h1>流氓广告</h1> <font size="7" color="#00ff00">这是广告,3秒后自动关闭</font> <script type="text/javascript"> window.setInterval("window.focus()", 3000); window.onunload = function() //关闭还弹广告 { window.open("1.html", "_blank", "location=no, menubar=no, scrollbars=no, status=no, titlebar=no, toolbar=no"); } </script> </body> </html>