0

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!

2
  • What does the output HTML look like? Serverside technology is irrelevant for opening popups on the client. Commented Oct 11, 2016 at 16:11
  • you mean BooksAuthor.aspx ? it's empty so far. I just want to open the window for now and it can be empty @Halcyon Commented Oct 11, 2016 at 16:14

2 Answers 2

2

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");
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, that works. although it doesn't seem to be the size i want. it is fully sized window
2

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");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.