Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Monday, 9 February 2015

Introduction:

Sometime we want to show a webpage or website in popup window on click of button or link button. This articles will show how to open page of your website or any other website in popup window that will appear on center of the parent window on click of link using JavaScript.

Use the following code in <head> tag as given below:
<head runat="server"
<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>
</head>

Use this code inside body tag of the page as per requirement:

<a href="http://www.maziksolutions.com" onclick="OpenPopUp(this.href,'mywin','1050','555','yes','center');return false" onfocus="this.blur()">Click here to open pop up window</a>

This example will open http://www.maziksolutions.com  in pop up window. Use this example as per your requirement. Replace the code with                                                                                                   e.g.
<a href="default2.aspx"  onclick="OpenPopUp(this.href,'mywin','1050','555','yes','center');return false"onfocus="this.blur()">Click here to open pop up window</a>


Now it will open default2.aspx page in pop up window.

Close pop up window:

Now we will learn how to close popup window using javascript. Use this link button code on the popup window page.

<asp:LinkButton id="lkCloseWindow" runat="server" Text="Close window"OnClientClick="window.close();"></asp:LinkButton>
Categories: ,

0 comments:

Post a Comment