locked
Setting height and width on window.open RRS feed

  • Question

  • User1016820894 posted

    I have a window that I am opening using the window.open command. I want to open it with the width as screen.width and height as screen.height. I have the code as follows:

        <script type="text/javascript">
            function InvokeWindow1() {
                   var heightnum = screen.height;
                   var widthnum = screen.width;
                   window.open("Login.aspx", "_blank", "width='+ widthnum +',height='+ heightnum +',top=20,left=20,location = 0,resizable=0,scrollbars=1,toolbar=0,menubar=0,status=0,titlebar=0");
                   window.open('', '_self', '');
                   self.close();
               } 
        </script>

    I call this function from code behind with the following command:

    Page.ClientScript.RegisterStartupScript(GetType(), "", "InvokeWindow1();", true);

    But when it opens the page it does not open appear to recognize the parameters. If I hard code the width/height number it works fine.

    What am I missing?

    FYI - I tried  adding Fullscreen = yes but that overrides everything.

    Wednesday, May 22, 2019 4:07 PM

Answers

  • User839733648 posted

    Hi baldwinjohn,

    According to your description and code, I've found that you've added the quotation marks are incorrectly in the window.open() function.

    Here is my working code:

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
        <script>
            function InvokeWindow1() {
                var heightnum = screen.height;
                var widthnum = screen.width;
                window.open("SubmitForm.aspx", "_blank", "width="+ widthnum +",height="+ heightnum +",top=20,left=20,location = 0,resizable=0,scrollbars=1,toolbar=0,menubar=0,status=0,titlebar=0");
                window.open('', '_self', '');
                self.close();
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        </form>
    </body>
    </html>
            protected void Button1_Click(object sender, EventArgs e)
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "InvokeWindow1();", true);
            }

    Best Regards,

    Jenifer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 23, 2019 9:57 AM

All replies

  • User753101303 posted

    Hi,

    Which  browser ? You are really testing with the same values ? Try F12 Console to check for a possible message.

    This kind of trick is often fragile and a bit questionable. Beyond a possible technical restriction, not keeping the user in control could be counter productive. IMHO it's much better to embrace how the web works rather than trying to go against.

    Edit: ah you mixed single and double quotes in the same string so your feature string is just used exactly as it is.

    Wednesday, May 22, 2019 4:50 PM
  • User839733648 posted

    Hi baldwinjohn,

    According to your description and code, I've found that you've added the quotation marks are incorrectly in the window.open() function.

    Here is my working code:

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
        <script>
            function InvokeWindow1() {
                var heightnum = screen.height;
                var widthnum = screen.width;
                window.open("SubmitForm.aspx", "_blank", "width="+ widthnum +",height="+ heightnum +",top=20,left=20,location = 0,resizable=0,scrollbars=1,toolbar=0,menubar=0,status=0,titlebar=0");
                window.open('', '_self', '');
                self.close();
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        </form>
    </body>
    </html>
            protected void Button1_Click(object sender, EventArgs e)
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "InvokeWindow1();", true);
            }

    Best Regards,

    Jenifer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 23, 2019 9:57 AM
  • User1016820894 posted

    Thanks Jenifer! That was it! I should have thought to try that but I had seen the single quotes on several sites that I had researched the issue on so figured they knew what they were talking about. HA.

    Thanks again! 

    Thursday, May 23, 2019 4:31 PM