我在1024x768下,弹出窗体居于屏幕中心,但是在600X800下,却是不是,
有没有办法在2个分辨率下都居中?

解决方案 »

  1.   

    var window_left = (screen.availWidth /2) - (window_width/2);
    var window_top = (screen.availHeight /2) - (window_height/2);
    var window_postion = "height=" + window_height +",width=" + window_width + ",left=" + window_left + ",top=" + window_top + ",scrollbars=no,status=no" ;
    window.open("a.aspx","_blank",window_postion);
      

  2.   

    window.showModalDialog("addnewframe.aspx","zhid","scroll:0;status:0;help:0;resizable:0;center=yes;dialogWidth:520px;dialogHeight:310px");
      

  3.   

    var window_left = (screen.availWidth /2) - (window_width/2);
    var window_top = (screen.availHeight /2) - (window_height/2);
    var window_postion = "height=" + window_height +",width=" + window_width + ",left=" + window_left + ",top=" + window_top + ",scrollbars=no,status=no" ;
    window.open("a.aspx","_blank",window_postion);
    找不到screen: 找不到类型或命名空间名称“screen”(是否缺少 using 指令或程序集引用?)
      

  4.   

    这个是客户段脚本,你应该用RESPONSE.WRITE
      

  5.   

    Response.Write("<script>window.open('login.aspx','','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=465,height=315,left=" + (screen.availWidth /2) - (465/2) + ",top=" + (screen.availHeight /2) - (315/2)+"');</script>");我这样写有错吗?
      

  6.   

    出现错误:找不到screen: 找不到类型或命名空间名称“screen”(是否缺少 using 指令或程序集引用?)
      

  7.   

    var window_left = (screen.availWidth /2) - (window_width/2);
    var window_top = (screen.availHeight /2) - (window_height/2);
    var window_postion = "height=" + window_height +",width=" + window_width + ",left=" + window_left + ",top=" + window_top + ",scrollbars=no,status=no" ;
    window.open("a.aspx","_blank",window_postion);
      

  8.   

    <a href="#" onclick='javascript:window.open("userinfo.aspx?User_Name=<%# DataBinder.Eval(Container.DataItem, "User_Name") %>","newname","width=600,height=450,top="+(screen.availHeight-450)/2+",left="+(screen.availWidth-600)/2).focus()'><%# DataBinder.Eval(Container.DataItem, "User_Name") %></a>
      

  9.   

    <script language="javascript">
    <!--
    function openwindow( url, winName, width, height)
    {
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ))
    {
    xposition = (screen.width - width) / 2;
    yposition = (screen.height - height) / 2;
    }
    theproperty= "width=" + width + "," 
    + "height=" + height + "," 
    + "location=0," 
    + "menubar=0,"
    + "resizable=1,"
    + "scrollbars=0,"
    + "status=0," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "screenx=" + xposition + "," //for Netscape
    + "screeny=" + yposition + "," //for Netscape
    + "left=" + xposition + "," //for IE
    + "top=" + yposition; //for IE 
    window.open( url,winName,theproperty );
    }
    //-->
    </script>
      

  10.   

    <a href="#" onclick='javascript:window.open("userinfo.aspx","newname","width=600,height=450,top="+(screen.availHeight-450)/2+",left="+(screen.availWidth-600)/2).focus()'>点击就可以弹出</a>大小可以自己调 width=600,height=450,看这个就明白了!
      

  11.   

    以上程序都出现:出现错误:找不到screen: 找不到类型或命名空间名称“screen”(是否缺少 using 指令或程序集引用?)
    怎么把上面这个错误解决
    (我是放在服务器端用Response.Write()里面施行的)
      

  12.   

    to 楼主:
    出现错误:找不到screen: 找不到类型或命名空间名称“screen”(是否缺少 using 指令或程序集引用?)都说了是客户端的,你咋还这样,
    StringBuilder sb = new StringBuilder();
    sb.Append("<script language=javascript>");
    sb.Append("window.open(\"default.htm\",null,\"status=yes,toolbar=no,menubar=no,location=no\");");
    sb.Append("window.opener = null;"); 
    sb.Append("window.close();");
    sb.Append("</script>"); 
    this.RegisterClientScriptBlock("redirectPage",sb.ToString());你把上面人家写的脚本赋给sb就可以了,
    你先在客户端调通在在后台赋给一string,再response.write 或RegisterClientScriptBlock就可以了!
      

  13.   

    this.RegisterClientScriptBlock(javascript:window.open("login.aspx","login","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=465,height=315,top="+(screen.availHeight-315)/2+",left="+(screen.availWidth-465)/2).focus());
    可以吗?
      

  14.   

    我要把代码放服务器端的这里:
    private void Page_Load(object sender, System.EventArgs e)

        if (Session["login"]==null)
      {  
    Response.Write("<script>window.moveTo(-9999,-9999);</script>");
    Response.Write("........")

                }
    }
    谁能给个完整的代码吗?
    谢谢,我脑子不好,领会不到上面几位大虾的高招...
      

  15.   

    Response.Write("<script Language=JavaScript>"); 
    string url="pass.aspx";       
    Response.Write("ChildWindow = window.open('"+url+"', '111', 'width=340,height=190,top=220,left=220,toolbar=no,status=no,location=no,menubar=no,directories=no,scrollbars=no,resizable=no')"); 
    Response.Write("</script>");
    自己参考一下,呵呵
      

  16.   

    这是脚本啊,老大你只要放在.aspx文件中就好了
      
      正确用法:
    <script >
    var window_left = (screen.availWidth /2) - (window_width/2);
    var window_top = (screen.availHeight /2) - (window_height/2);
    var window_postion = "height=" + window_height +",width=" + window_width + ",left=" + window_left + ",top=" + window_top + ",scrollbars=no,status=no" ;
    window.open("a.aspx","_blank",window_postion);
    </scirpt>
      

  17.   

    js脚本,和aspx没关系的,你存成一个html测试一下吧
      

  18.   

    放在aspx中的话,肯定要<body onload=open()>
    那样的话我不是返回首页就要登陆??我放到cs中是为了方便用session判断有没有登陆过,登陆过就不弹出登陆小窗口,反之,出先弹出小登陆窗口,并且不论在1024x768还是800X600下都能居屏幕中间.