Click here to Skip to main content
11,484,162 members (67,901 online)
Click here to Skip to main content

Starting your website in a popup window

, 2 Jul 2008 CPOL 16.5K 278 22
Rate this:
Please Sign up or sign in to vote.
You can start your website in a popup window (without having user to click even a single button)

Introduction

ASP.net has provided very rich environment for web development; and its keep on improving the development experience.

Most of the times we come across a problem to compare the look & feel of windows application with web application (because our clients ask us to do that Frown | :( ) and I am sure that it might have happened with most of us (especially developers working on re-engineering projects)

Details

We were in need to find a solution to open very first page of our site as a popup window, and the only solution I got is to take help from my girlfriend...... i.e. Javascript Smile | :)

Using the code

Using the following steps, you can easily achieve this feature.

  1. Add a default.htm page in root of your web project.
  2. Write the javascript code on top of that page (ref. attached project also).
  3. Give name & path (if required) of the page you want to open in popup (most of times its default.aspx)
  4. Make default.htm as start page for that site.

Hooray.... you have successfully configured popup functionality for you website.

<script type="text/javascript" language="'javascript'">
    window.onload = poponload; 
    function poponload()
    {   
        try
        {                                
            //Set variables, version is IE version number
            var ua = window.navigator.appVersion;
            var msie = ua.indexOf ( "MSIE " );
            var version = ua.substring(msie+5,msie+6);
            //Open new window
            var now = new Date();
            var hour        = now.getHours();
            var minute      = now.getMinutes();
            var second      = now.getSeconds();
            var monthnumber = now.getMonth();
            var monthday    = now.getDate();
            var year        = now.getYear();
            var winName='master'+year+monthnumber+hour+minute+second;/*making window name dynamic*/
            /*fo in query parameter is used to tell that this site is first opening, returnURL will be used in case of forms authentication*/
            var win = window.open ('default.aspx?fo=1', winName, "fullscreen=no,scrollbars=1,resizable=1,status=1,dependent=yes,alwaysRaised=yes");
            if(!win)
            {
                alert("Popups are blocked.\nMust allow popups to run the application");
            }
            else
            {              
                //Check version number and run correct code
                if (version >= "7")
                {
                    if (win) 
                    {
                        window.open('', '_parent','');
                        window.close();
                    }
                    
                } 
                else 
                {
                    self.opener = this;
                    setTimeout('self.close()',500);
                };
            }
        }
        catch(ex){alert(ex.message);}
    }
</script>
         

Checking Popups are blocked

var win = window.open ('default.aspx?fo=1', winName, "fullscreen=no,scrollbars=1,resizable=1,status=1,dependent=yes,alwaysRaised=yes");
            if(!win)
            {
                alert("Popups are blocked.\nMust allow popups to run the application");
            } 

You can also use the above code snippet in your application only to check that whether any respective popup is opening in browser or it is blocked by the browser / google toolbar.

Browsers Compatible

  • IE6 +

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Surjit Singh Dadhwal
Software Developer (Senior)
India India
Programming is my passion and C# is my friend, Javascript is my first crush..
Surprized!!!, don't be....
I love doing programming and writing efficient code, with the help of code project; I am able to share my experiences too with you all.

Thanks for visiting and voting this post.. [Smile | :) ]

Comments and Discussions

 
GeneralThis is Great! Pin
Heywood3-Jul-08 4:49
memberHeywood3-Jul-08 4:49 
GeneralRe: This is Great! Pin
Surjit Singh Dadhwal29-Jul-08 11:59
memberSurjit Singh Dadhwal29-Jul-08 11:59 
Generalgreate Pin
Abhijit Jana3-Jul-08 1:41
memberAbhijit Jana3-Jul-08 1:41 
GeneralYour article really helped us!!! Keep it up. Pin
Vinit Singh27-May-08 0:09
memberVinit Singh27-May-08 0:09 
General[Message Removed] Pin
Mojtaba Vali23-May-08 22:59
memberMojtaba Vali23-May-08 22:59 
GeneralRe: starting step Pin
Surjit Singh Dadhwal25-May-08 20:37
memberSurjit Singh Dadhwal25-May-08 20:37 
GeneralNo visible use Pin
Xiotox23-May-08 14:05
memberXiotox23-May-08 14:05 
GeneralRe: No visible use Pin
Surjit Singh Dadhwal25-May-08 20:41
memberSurjit Singh Dadhwal25-May-08 20:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 3 Jul 2008
Article Copyright 2008 by Surjit Singh Dadhwal
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid