fkr
fkr

Reputation: 155

Javascript code to open pop-up window on button click?

I want to know how to write a javascript code that will open a new 600*300 pop-up window on button click.

Let's say i have a open-up button in my Books.aspx ...and when i click "display", i want a few books to be display in the pop-up window, which is another web-form called BooksAuthor.aspx

This is what i've tried so far:

Option 1

<asp:TextBox ID="text1" runat="server"></asp:TextBox>
<asp:Button ID="button1" runat="server" onClick="window.open('BooksAuthor.aspx');" Text="Display" /><br /><br />

Option 2

<asp:TextBox ID="text1" runat="server"></asp:TextBox>
<asp:Button ID="button1" runat="server" onClick="openWindow();"Text="Display" /><br /><br />

<script type="text/javascript">
function openWindow()
{
    window.open("BooksAuthor.aspx", "status=1,width=600,height=300");
}

Nothing seems to be working. Any ideas?

Thank you!

Upvotes: 0

Views: 13578

Answers (2)

Nitin Kumar
Nitin Kumar

Reputation: 898

To open custom sized window the proper syntax is

window.open(URL,name,specs,replace)

EX:-window.open("BooksAuthor.aspx", "MsgWindow", "width=600,height=300");

Upvotes: 2

Ram
Ram

Reputation: 504

you have to call javascript on onClientClick

<asp:Button ID="button1" runat="server" OnClientClick="window.open('BooksAuthor.aspx');" Text="Display" /><br /><br />

Or

<asp:Button ID="button1" runat="server" OnClientClick="openWindow();" Text="Display" /><br /><br />

<script type="text/javascript">
function openWindow() {
    window.open("BooksAuthor.aspx", "status=1,width=600,height=300");
}

Upvotes: 2

Related Questions