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.
- Add a default.htm page in root of your web project.
- Write the javascript code on top of that page (ref. attached project also).
- Give name & path (if required) of the page you want to open in popup (most of times its default.aspx)
- 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= /*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 ( 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( window.close();
}
}
else
{
self.opener = this;
setTimeout( };
}
}
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