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!
-
What does the output HTML look like? Serverside technology is irrelevant for opening popups on the client.Halcyon– Halcyon2016年10月11日 16:11:08 +00:00Commented 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 @Halcyonfkr– fkr2016年10月11日 16:14:08 +00:00Commented Oct 11, 2016 at 16:14
2 Answers 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
fkr
thanks, that works. although it doesn't seem to be the size i want. it is fully sized window
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");
answered Oct 11, 2016 at 16:41
Nitin Kumar
9087 silver badges22 bronze badges
Comments
default