How to open and close pop up window in asp.net using javascript?

How to display popup window in ASP.Net?

I try and got the solution is below:

You just copy the below javascript and paste into head tag.


<script language="javascript" type="text/javascript">
var win = null;
function OpenPopUp(mypage, myname, w, h, scroll, pos) {
if (pos == "random") { LeftPosition = (screen.width) ? Math.floor(Math.random() * (screen.width - w)) : 100;

TopPosition = (screen.height) ? Math.floor(Math.random() * ((screen.height - h) - 75)) : 100; }
if (pos == "center") { LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100; TopPosition =

(screen.height) ? (screen.height - h) / 2 : 100; }
else if ((pos != "center" && pos != "random") || pos == null) { LeftPosition = 0; TopPosition = 20 }
settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' +

scroll + ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
win = window.open(mypage, myname, settings);
}
</script>

Then copy the below code and paste into body tag where you want the link to appear.


<a href="http://www.code.top10idea.com"  onclick="OpenPopUp(this.href,'mywin','1050','555','yes','center');return false"

onfocus="this.blur()">Click here to Display pop up window</a>
Above example will open http://www.code.top10idea.com in popup window. But if you want display popup in another page so you just replace your website like below:

<a href="default2.aspx"  onclick="OpenPopUp(this.href,'mywin','1050','555','yes','center');return false"

onfocus="this.blur()">Click here to Display pop up window</a>

About the Author

avatar