window.open()使用集锦

       
    1、弹出窗口的参数设置

  <SCRIPT LANGUAGE="javascript">
  <!--
  window.open ('popuppage.html', 'windowsname', 'height=100, width=400, top=0,  left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no,status=no') //这句要写成一行
  -->
  </SCRIPT>
  
  参数解释:
  
  'popuppage.html' ------------弹出窗口的文件名;
  'windowsname' --------------弹出窗口的名字(不是文件名),非必须,可用空''代替;
  height=100 --------------------窗口高度;
  width=400 ---------------------窗口宽度;
  top=0 ---------------------------窗口距离屏幕上方的象素值;
  left=0 ---------------------------窗口距离屏幕左侧的象素值;
  toolbar=no --------------------是否显示工具栏,yes为显示;
  menubar=no -----------------是否显示菜单栏,yes为显示;
     scrollbars=no----------------是否显示滚动栏,yes为显示;
  resizable=no -----------------是否允许改变窗口大小,yes为允许;
  location=no ------------------是否显示地址栏,yes为允许;
  status=no --------------------是否显示状态栏内的信息(通常是文件已经打开),yes为允许;


    2、弹出窗口的10秒后定时关闭。
  
  将如下代码加入窗口的'popuppage.html'文件的<head>区:

  <script language="javascript">
  function closeit()
  {
  setTimeout("self.close()",10000) //1秒=1000毫秒
  }
  </script>
 

  3、动态改变弹出窗口的内容

  
  <SCRIPT LANGUAGE="javascript">
  function openwin()
  {
  OpenWindow=window.open("", "windowsname", height=200, width=200);
  
  OpenWindow.document.write("<HTML>")
  OpenWindow.document.write("<BODY>")
  OpenWindow.document.write("<h1>Hello!</h1>")
  OpenWindow.document.write("</BODY>")
  OpenWindow.document.write("</HTML>")
  OpenWindow.document.close()
  }
  </SCRIPT>
  
  4、弹出窗口用Cookie控制只显示一次。
  
  将如下代码加入调用弹出窗口的<HEAD>区:

  <script>
  function openwin(){
  window.open("popuppage.html","","width=200,height=200")
  }

  function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (documents.cookie.length > 0) {
  offset = documents.cookie.indexOf(search)
  if (offset != -1) {
  offset += search.length
  end = documents.cookie.indexOf(";", offset);
  if (end == -1)
  end = documents.cookie.length;
  returnvalue=unescape(documents.cookie.substring(offset, end))
  }
  }
  return returnvalue;
  }  
 
  function loadpopup(){
  if (get_cookie('popped')==''){
  openwin()
  documents.cookie="popped=yes"
  }
  }

  </script>

  然后,用<body οnlοad="loadpopup()">调用。

  
  5、弹出窗口的关闭

  <script>
   window.close()
  </script>
  
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值