技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> JavaScript --> 弹出窗口的兼容方案

弹出窗口的兼容方案

浏览:1842次  出处信息

记录一下弹出窗口的兼容方案

以下是代码片段:

<!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>
 <style type="text/css">
 html, body {
  margin: 0;
  padding: 0;
 }
 body {
 }
 #div1 {
  height: 2000px;
 }
 #floatedLayer {
  position: fixed;
  _position: absolute;
 }
 </style>
</head>
<body>
 <div id="floatedLayer">
  <iframe src="demo.html" width="580" height="542" frameborder="no"></iframe>
 </div>
 <div id="div1"></div>
 <script type="text/javascript">
  var floatedLayer = document.getElementById("floatedLayer");
  function adjustPopupWin() {
   var height = document.documentElement.clientHeight,
    width = document.documentElement.clientWidth;
   floatedLayer.style.left = Math.max((width - floatedLayer.offsetWidth) / 2, 0) + "px";
   floatedLayer.style.top = Math.max((height - floatedLayer.offsetHeight) / 2, 0) + "px";
  }
 </script>
 <!--[if IE 6]>
 <script type="text/javascript">
  function adjustPopupWin() {
   var height = document.documentElement.clientHeight,
    width = document.documentElement.clientWidth;
   floatedLayer.style.left = Math.max((width - floatedLayer.offsetWidth) / 2, 0) + document.documentElement.scrollLeft + "px";
   floatedLayer.style.top = Math.max((height - floatedLayer.offsetHeight) / 2, 0) + document.documentElement.scrollTop + "px";
  }
  window.onscroll = adjustPopupWin;
 </script>
 <![endif]-->
 <script type="text/javascript">
  window.onresize = adjustPopupWin;
  adjustPopupWin();
 </script>
</body>
</html>

建议继续学习:

  1. 异步完成后新开窗口    (阅读:2908)
  2. IE 中无提示关闭窗口的方法    (阅读:1882)
  3. 模式化窗口    (阅读:1835)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1