Click here to Skip to main content
Licence CPOL
First Posted 22 May 2008
Views 12,309
Downloads 158
Bookmarked 21 times

Starting your website in a popup window

By | 2 Jul 2008 | Article
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 :( ) 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 :)

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)

About the Author

Surjit Singh Dadhwal

Software Developer (Senior)

India India

Member

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 | :) ]

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThis is Great! PinmemberHeywood3:49 3 Jul '08  
GeneralRe: This is Great! PinmemberSurjit Singh Dadhwal10:59 29 Jul '08  
Generalgreate PinmemberAbhijit Jana0:41 3 Jul '08  
GeneralYour article really helped us!!! Keep it up. PinmemberVinit Singh23:09 26 May '08  
General[Message Removed] PinmemberMojtaba Vali21:59 23 May '08  
GeneralRe: starting step PinmemberSurjit Singh Dadhwal19:37 25 May '08  
GeneralNo visible use PinmemberXiotox13:05 23 May '08  
GeneralRe: No visible use PinmemberSurjit Singh Dadhwal19:41 25 May '08  

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.

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