日期:2014-05-16  浏览次数:20327 次

javascript关闭窗口(兼容firefox,IE)

javascript关闭窗口,可以用下面简单的代码:

Html代码 复制代码
  1. <a?href="javascript:self.close()">关闭窗口</a>????
<a href="javascript:self.close()">关闭窗口</a>  


我在IE7下测试通过,但是firefox3.0却不行。
难道firefox不支持在href中直接写JavaScript?于是改成下面的样子:

Html代码 复制代码
  1. <a?href="javascript:alert('Hello?World')">弹出窗口</a>????
<a href="javascript:alert('Hello World')">弹出窗口</a>  


这次IE7和firefox下测试都通过。那就不是href中直接写JavaScript的原因了。
继续测试firefox怎么关闭自身窗口

改成了如下代码

Html代码 复制代码
  1. <!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"???? ??
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">?? ??
  3. <html?xmlns="http://www.w3.org/1999/xhtml">?? ??
  4. <head>?? ??
  5. <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>?? ??
  6. <script?type=