一个强制弹窗代码

来源:本站整理  作者:不详
摘要:用本程序弹出的窗口将不会被广告拦截软件拦截,但有一个缺点:你无法象对window.open弹出的窗口那样对外观进行定制。…

用本程序弹出的窗口将不会被广告拦截软件拦截,但有一个缺点:你无法象对window.open弹出的窗口那样对外观进行定制。

* 你当然也可以在使用前实例化一个ForceWindow对象:

* var myWindow = new ForceWindow();

* 这样来使用:

* myWindow.pop("URL");

* 本程序在 IE 5+、Firefox 1.0、Mozilla 1.7.5、Netscape 7.2、Opera 7.23 下测试正常,但目前没有“冲破”Firefox的拦截。

*/

演示地址 :http://bbs.cncome.com/click.html

将下面的代码保存为一个.JS文件

CODE:  /**

* 定义ForceWindow类构造函数

* 无参数

* 无返回值

*/

function ForceWindow ()
{
  if (!(this.isMsie = (/MSIE/).test(navigator.appVersion)))
  {
  this.f = document.createElement("FORM");
  this.f.target = "_blank";
  this.f.method = "post";
  document.documentElement.insertBefore(this.f, document.documentElement.childNodes[0]);
  }
}

/**

* 定义pop方法

* 参数sUrl:字符串,要打开窗口的URL。

* 无返回值

*/

ForceWindow.prototype.pop = function (sUrl)
{
  if (this.isMsie)
  {
  var dialogConent  = "about:";
  dialogConent += "<a href='" + sUrl + "' target='_blank' id='iecn' style='display:none;'>iecn</a>";
  dialogConent += "<script language='JavaScript' type='text/javascript'>";
  dialogConent += "document.getElementById('iecn').click();window.close();</script>";
  window.showModalDialog(dialogConent, "", "width:1px;height:1px;left:0px;top:0px;");
  }
  else
  {
  this.f.action = sUrl;
  this.f.submit();
  }
}

/**

* 实例化一个ForceWindow对象并做为window对象的一个子对象以方便调用

* 定义后可以这样来使用:window.force.pop("URL");

*/

window.force = new ForceWindow();

测试部分.

CODE:   <html>
<head>
<title>ForceWindow测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript" type="text/javascript"
src="ForceWindow-1.0.2.iclass.js"></script>
<script language="JavaScript" type="text/javascript">
window.onload = function () {
  window.force.pop("http://bbs.cncome.com");
}
</script>
</head>
<body>
<h3>强制弹出窗口测试</h3>
<p>打开这页,如果弹出了新世纪平台的官方站,即表示正常.顺带去体验下Web下的windows操作系统吧^_^</p>
<button onclick="window.force.pop('http://newcn.nc21.cn');">
创新技术,引领未来 :-)</button>
</body>
</html>

【相关文章】好搜一下
历经8年 微软.NET更换新形象

历经8年 微软.NET更换新形象

在历经了8年风霜后,微软日前推出了.NET系列产品的新版Logo,设计风格和Si…