zoukankan      html  css  js  c++  java
  • Window.open()方法控制窗口最大小化宽度滚动条参数详解

    1、最基本方法调用代码

    window.open('page.html');

    2、设置参数后的弹出窗口

     window.open("index.html",'newwindow', 'height=622, width=1000, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');

    参数解释:
            window.open 弹出新窗口的命令; 
      'index.html' 弹出窗口的文件名; 
      'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空''代替; 
      height=100 窗口高度; 
      width=400 窗口宽度; 
      top=0 窗口距离屏幕上方的象素值; 
      left=0 窗口距离屏幕左侧的象素值; 
      toolbar=no 是否显示工具栏,yes为显示; 
      menubar,scrollbars 表示菜单栏和滚动栏。 
      resizable=no 是否允许改变窗口大小,yes为允许; 
      location=no 是否显示地址栏,yes为允许; 
      status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;

    3, 用函数控制弹出窗口
        下面是一段完整的代码

    <html> 
      <head> 
          <script LANGUAGE="JavaScript"> 
              function openwin() { 
                  window.open("index.html",'newwindow', 'height=622, width=1000, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
              } 
          </script> 
      </head> 
      <body onload="openwin()"> 
          任意的页面内容... 
      </body> 
    </html> 

     解释:这里定义了一个函数openwin(), 函数内容就是打开一个窗口。在调用它之前没有任何用途。怎么调用呢?
       
       方法一:<body οnlοad="openwin()"> 浏览器读页面时弹出窗口;
       方法二:<body οnunlοad="openwin()"> 浏览器离开页面时弹出窗口;
       方法三:用一个连接调用:
                  <a href="#" οnclick="openwin()"> 打开一个窗口</a>
                  注意:使用的"#"是虚连接。
       方法四:用一个按扭调用:
                   <input type="button" οnclick="openwin()" value="打开窗口" />

    4, 弹出两个窗口
        对代码稍微改动如下:

    <script LANGUAGE="JavaScript"> 
      function openwin() { 
      window.open ("page.html", "newwindow", "height=100, width=100, top=0, left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=n o, status=no")//写成一行 
      window.open ("page2.html", "newwindow2", "height=100, width=100, top=100, left=100,toolbar=no, menubar=no, scrollbars=no, resizable=no, loca tion=no, status=no")//写成一行 
      } 
      </script>

      为避免弹出的2个窗口覆盖,用top和left控制一下弹出的位置不要相互覆盖即可。最后用上面的说过的四种方法调用即可。
          注意:2个窗口的name(newwindow与 newwindow2)不要相同,或者干脆全部为空。

    5, 主窗口打开文件1.htm,同时弹出小窗口page.html
        如下代码加入主窗口<head>区:
       

    function openwin()
        {
         window.open("page.html","","width=200,height=200") 
        }

     加入body区:

    <a href="1.htm" onclick="openwin()">open</a>

    6, 弹出的窗口之定时关闭控制
        将一小段代码加入弹出的页面(注意是加入page.html的HTML中,可不是主页面中,否则......),让它在10秒后自动关闭是不是更酷了?

    function closeit()
        {
        setTimeout("selft.close()", 10000)   //毫秒
        }

     然后,在body 中添加:<body οnlοad="closeit()">即可。

    7, 在弹出窗口中加上一个关闭按扭
       

     <input type="button" value="关闭" onclick="window.close()">

    8, 内包含的弹出窗口---一个页面两个窗口
        上面的例子都包含两个窗口,一个是主窗口,另一个是弹出的小窗口。通过下面的例子,你可以在一个页面内完成上面的效果。

     <html> 
      <head> 
      <SCRIPT LANGUAGE="JavaScript"> 
      function openwin() 
      { 
      OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no ,scrollbars="+scroll+",menubar=no"); 
      //写成一行 
      OpenWindow.document.write("<TITLE>例子</TITLE>") 
      OpenWindow.document.write("<BODY BGCOLOR=#ffffff>") 
      OpenWindow.document.write("<h1>Hello!</h1>") 
      OpenWindow.document.write("New window opened!") 
      OpenWindow.document.write("</BODY>") 
      OpenWindow.document.write("</HTML>") 
      OpenWindow.document.close() 
      } 
      </SCRIPT> 
      </head> 
      <body> 
      <a href="#" onclick="openwin()">打开一个窗口</a> 
      <input type="button" onclick="openwin()" value="打开窗口"> 
      </body> 
      </html> 

       OpenWindow.document.write()里面的代码不就是标准的HTML吗?只要按照 格式写更多的行即可。千万注意多一个标签或少一个标签就会出现错误。记得用 OpenWindow.document.close()结束啊。 

    9, 终极应用---弹出的窗口这Cookie控制
        回想一下,上面的弹出窗口虽然酷,但是有一点小毛病,比如你将上面的脚本放在一个需要频繁经过的页面里(例如首页),那么每次刷新这个页面,窗口都会弹出一次,是不是非常烦人?
        有解决的办法吗?我们使用cookie来控制即可。
        首先,将如下代码加入主页面的Html的head区:

     <html> 
      <head> 
      <SCRIPT LANGUAGE="JavaScript"> 
      function openwin() 
      { 
      OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no ,scrollbars="+scroll+",menubar=no"); 
      //写成一行 
      OpenWindow.document.write("<TITLE>例子</TITLE>") 
      OpenWindow.document.write("<BODY BGCOLOR=#ffffff>") 
      OpenWindow.document.write("<h1>Hello!</h1>") 
      OpenWindow.document.write("New window opened!") 
      OpenWindow.document.write("</BODY>") 
      OpenWindow.document.write("</HTML>") 
      OpenWindow.document.close() 
      } 
      </SCRIPT> 
      </head> 
      <body> 
      <a href="#" onclick="openwin()">打开一个窗口</a> 
      <input type="button" onclick="openwin()" value="打开窗口"> 
      </body> 
      </html> 

    最后,用<body οnlοad="loadpopup()">

    写到这里弹出窗口的制作和应用技巧基本上算是完成了!

    转载:https://blog.csdn.net/soso3056/article/details/86375487

    --------------------------------------------------------------------------------------------------------------------------------------------

    <h1>qq授权登录</h1>
         <a href="#" onclick='toLogin()' ><img class="avatar size-S" src="/static/qq.jpg" title="QQ登录">QQ登录</a>
    <script>
     function toLogin()
     {
         //以下为按钮点击事件的逻辑。注意这里要重新打开窗口
         //否则后面跳转到QQ登录,授权页面时会直接缩小当前浏览器的窗口,而不是打开新窗口
         var A=window.open("{:url('wpapi/register/qq_login')}","TencentLogin",
             "width=450,height=320,menubar=0,scrollbars=1, top=100,left=50,resizable=1,status=1,titlebar=0,toolbar=0,location=1");
     }
    </script>
  • 相关阅读:
    JUnit4_2
    软件工程
    Java核心API需要掌握的程度
    VS2008工具箱不显示的解决方法
    SQLServer 2005中的Row_Number()分页
    关于UITableView的一点儿新认识
    二叉树的建立和遍历
    In App Purchases(IAP 应用程序內购买): 完全攻略 (转)
    [转]内存分配函数 _alloc/malloc/calloc
    ObjectiveC学习笔记
  • 原文地址:https://www.cnblogs.com/yehuisir/p/13625397.html
Copyright © 2011-2022 走看看