Project Description
API to open Web Browser window at specified location, set its size and other attributes

Working Demo* : http://webinfocentral.com (Select menu item" TECH->MOTOSPORT)

Project contains:
1. C# Module (InfosoftOpenWindowJS.cs)
2. Sample ASP.NET DEMO Web page (Default.aspx with corresponding code behind Default.aspx.cs) to demonstrate the functionality
C# Code module to be placed in App_Code directory
//******************************************************************************
// Module           :   InfosoftOpenWindowJS.cs
// Author           :   Alexander Bell
// Copyright        :   2007-2009 Alexander Bell
// Date Created     :   02/15/2007
// Last Modified    :   10/30/2009

// Description      :   Open Web Page and set Window attributes/position
//                  :   using Javascript

//******************************************************************************
// DISCLAIMER: This Application is provide on AS IS basis without any warranty
//******************************************************************************


using System;
using System.Web;

///*****************************************************************************
/// <summary>Open Web page and set Window attributes using Javascript</summary> 
public static class OpenWindowJS
{
    #region Open Full Screen Window
    /// <summary>Open Browser Window: Full Screen</summary>
    /// <param name="URL">string</param>
    /// <param name="Name">string</param>
    /// <param name="FullScreen">bool</param>
    /// <param name="MenuBar">bool</param>
    /// <param name="Resizable">bool</param>
    /// <param name="Toolbar">bool</param>
    /// <param name="Location">bool</param>
    /// <param name="StatusBar">bool</param>
    /// <param name="Copyhistory">bool</param>
    /// <param name="ScrollBalr">bool</param>
    /// <returns>string</returns>
    public static string GetScript
                   (string URL, 
                    string Name, 
                    bool FullScreen, 
                    bool MenuBar,
                    bool Resizable,
                    bool Toolbar,
                    bool Location,
                    bool StatusBar,
                    bool Copyhistory,
                    bool ScrollBar)
    {
      string ret = "javascript:void window.open ('";
      ret = ret + URL + "', '" + Name + "', '";
      ret = ret + "fullScreen=" + ((FullScreen) ? "1" : "0") + ",";
      ret = ret + "resizable=" + ((Resizable) ? "1" : "0") + ","; 
      ret = ret + "menuBar=" + ((MenuBar) ? "1" : "0") + ",";
      ret = ret + "toolbar=" + ((Toolbar) ? "1" : "0") + ",";
      ret = ret + "location=" + ((Location) ? "1" : "0") + ",";
      ret = ret + "statusBar=" + ((StatusBar) ? "1" : "0") + ",";
      ret = ret + "copyhistory=" + ((Copyhistory) ? "1" : "0") + ",";
      ret = ret + "scrollBar=" + ((ScrollBar) ? "1" : "0") + ",";
      ret = ret +  "')";
      return ret;
    }
    #endregion

    #region Open Window with adjustable Width/Height
    /// <summary>Open Browser Window, set Width/Height</summary>
    /// <param name="URL">string</param>
    /// <param name="Name">string</param>
    /// <param name="Width">string</param>
    /// <param name="Height">string</param>
    /// <param name="MenuBar">bool</param>
    /// <param name="Toolbar">bool</param>
    /// <param name="Location">bool</param>
    /// <param name="StatusBar">bool</param>
    /// <param name="Copyhistory">bool</param>
    /// <param name="ScrollBar">bool</param>
    /// <returns>string</returns>
    public static string GetScript
                   (string URL,
                    string Name,
                    string Width,
                    string Height,
                    bool MenuBar, 
                    bool Toolbar,
                    bool Location,
                    bool StatusBar,
                    bool Copyhistory,
                    bool ScrollBar)
    {
        string ret = "javascript:void window.open ('";
        ret = ret + URL + "', '" + Name + "', '";
        
        ret = ret + "resizable=1,";
        ret = ret + "width=" + Width + ","; 
        ret = ret + "height=" + Height + ",";
        ret = ret + "menuBar=" + ((MenuBar) ? "1" : "0") + ",";
        ret = ret + "toolbar=" + ((Toolbar) ? "1" : "0") + ",";
        ret = ret + "location=" + ((Location) ? "1" : "0") + ",";
        ret = ret + "statusBar=" + ((StatusBar) ? "1" : "0") + ",";
        ret = ret + "copyhistory=" + ((Copyhistory) ? "1" : "0") + ",";
        ret = ret + "scrollBar=" + ((ScrollBar) ? "1" : "0") + ",";
        ret = ret + "')";
        return ret;
    }


    /// <summary>
    /// Open Browser Window, set Width/Height and position Left/Top
    /// </summary>
    /// <param name="URL">string</param>
    /// <param name="Name">string</param>
    /// <param name="Width">string</param>
    /// <param name="Height">string</param>
    /// <param name="MenuBar">bool</param>
    /// <param name="Toolbar">bool</param>
    /// <param name="Location">bool</param>
    /// <param name="StatusBar">bool</param>
    /// <param name="Copyhistory">bool</param>
    /// <param name="ScrollBar">bool</param>
    /// <param name="AlwaysRaised">bool</param>
    /// <param name="Dependent">bool</param>
    /// <param name="Left">string</param>
    /// <param name="Top">string</param>
    /// <returns>string</returns>
    public static string GetScript
                   (string URL,
                    string Name,
                    string Width,
                    string Height,
                    bool MenuBar,
                    bool Toolbar,
                    bool Location,
                    bool StatusBar,
                    bool Copyhistory,
                    bool ScrollBar,
                    bool AlwaysRaised,
                    bool Dependent,
                    string Left,
                    string Top)
    {
        string ret = "javascript:void window.open ('";
        ret = ret + URL + "', '" + Name + "', '";

        ret = ret + "resizable=1,";
        ret = ret + "width=" + Width + ",";
        ret = ret + "height=" + Height + ",";
        ret = ret + "menuBar=" + ((MenuBar) ? "1" : "0") + ",";
        ret = ret + "toolbar=" + ((Toolbar) ? "1" : "0") + ",";
        ret = ret + "location=" + ((Location) ? "1" : "0") + ",";
        ret = ret + "statusBar=" + ((StatusBar) ? "1" : "0") + ",";
        ret = ret + "copyhistory=" + ((Copyhistory) ? "1" : "0") + ",";
        ret = ret + "scrollBar=" + ((ScrollBar) ? "1" : "0") + ",";
        ret = ret + "alwaysRaised=" + ((AlwaysRaised) ? "1" : "0") + ",";
        ret = ret + "dependent=" + ((Dependent) ? "1" : "0") + ",";
        ret = ret + "left=" + Left + ",";
        ret = ret + "top=" + Top + ",";
        ret = ret + "')";
        return ret;
    }
    #endregion
}
///*****************************************************************************************
Demo Web Page
<%@ Page Language="C#" 
AutoEventWireup="true"  
CodeFile="Default.aspx.cs" 
Inherits="_Default" %>

<!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 runat="server">
        <title>OPEN NASCAR MAP | DEMO</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" runat="server" Text="OPEN NASCAR MAP: FULL SCREEN" />
            <br />
            <asp:Button ID="Button2" runat="server" Text="OPEN NASCAR MAP: 800/600" />
            <br />
            <asp:Button ID="Button3" runat="server" Text="OPEN NASCAR MAP AT: X=100; Y=50" />
        </div>
        </form>
    </body>
</html>
Code behind page

//******************************************************************************
// Module           :   Default.aspx.cs
// Author           :   Alexander Bell
// Copyright        :   2007-2009 Alexander Bell
// Date Created     :   02/15/2007
// Last Modified    :   10/30/2009

// Description      :   code behind (ASP.NET)

//******************************************************************************
// DISCLAIMER: This Application is provide on AS IS basis without any warranty
//******************************************************************************

//******************************************************************************
// TERMS OF USE     :   This module is copyrighted.
//                  :   You can use it at your sole risk provided that you keep
//                  :   the original copyright note.
//******************************************************************************
using System;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // set target URL
        string _URL = "http://www.webinfocentral.com/_RESOURCES/NascarMap.aspx";
        
        // get Javascript to open full screen browser window
        string _scriptJS1 =
        OpenWindowJS.GetScript(_URL, "NascarMap", true, false, false, false, 
        false, false, false, false);

        // get Javascript to open web page with predfined size (800x600)
        string _scriptJS2 =
        OpenWindowJS.GetScript(_URL,"NascarMap1", "800", "600", false,false,
        false,false,false,false);

        // get Javascript to open web page with predfined size (800x600)
        // at specified location: X=100, Y=50
        string _scriptJS3 =
        OpenWindowJS.GetScript(_URL, "NascarMap2", "800", "600", false, false, 
        false, false, false, false, true, true, "100", "50");

        // add script to onclick event of page control
        Button1.Attributes.Add("onclick", _scriptJS1);

        // add script to onclick event of page control
        Button2.Attributes.Add("onclick", _scriptJS2);

        // add script to onclick event of page control
        Button3.Attributes.Add("onclick", _scriptJS3);
    }
}

Web Page Javascript Window.Open ASP.NET C# HTML IE FireFox Safari Chrome Bing

Last edited Feb 18, 2015 at 1:29 AM by DrABELL, version 10