Help with opening a new window

  • Thread starter Thread starter REB
  • Start date Start date
R

REB

Can someone help me with adding some javascript functionality to a button?

What would the proper syntax for for (please help with the javascript I am
rusty) for doing this:

btnMyButton.Attributes.Add("onclick", **Open a new window with no toolbar or
address bar to address http://mysite.com/viewer.aspx?key= +
mydropdownlist.SelectedValue.ToString()**);

If possible I would want the window to be small and in the center of the
screen.

Thanks,
REB
 
window.open is what you want.
See a clientside/javascript group though, or even a google search will get
you what you are after.
 
REB,

If you'd like, I have a "Javascript" project available on my web site:
www.aboutfortunate.com. The project's full source code is downloadable and
everything on my site is free. It includes many commonly used javascripts
including one that easily lets you open new windows on a button click.

At the least it's source code will help you figure out how to write your own
scripts.

Just click the "Code Library" link in the upper right corner of the page and
then click the "Javascript" button in the menu that appears on the left.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
This works but the window after opening loses focus immediately and
disappears behind the calling page.

btnChangeDriverLocation.Attributes.Add ("onClick",
"window.open('ChangeLocation.aspx','', 'width=400, height=300');");

Anyone know how I can keep the window on top of the calling page?
 
I tried this:
btnChangeDriverLocation.Attributes.Add ("onClick", "var mywindow
=window.open('ChangeLocation.aspx','', 'width=400, height=300');
mywindow.focus();");

No Luck, the pop-up still disappears behind the calling page.
 
Run code like this in PageLoad.

'Open a centered child window if About button is clicked:

btnAbout.Attributes("OnClick") =
"javascript:lnWidth=500;lnHeight=400;lnTop=(screen.Height-lnHeight)/2;lnLeft
=(screen.Width-lnWidth)/2;window.open('About.aspx','MyAboutBox','toolbar=0,m
enubar=0,status=0,scrollbars=1,resizable=1,width='+lnWidth+',height='+lnHeig
ht+',top='+lnTop+',left='+lnLeft+'');return false;"


btnAbout.Attributes("OnMouseOver") = "javascript:window.status='Open
the About window';"
btnAbout.Attributes("OnMouseOut") = "javascript:window.status='';"

=======================================================================
Bonus:
'open the print dialog box when the printer image is clicked:
imgPrinter.Attributes("OnClick") = "javascript:window.print();"
imgPrinter.Attributes("OnMouseOver") = "javascript:window.status='Open
the Print Dialog box';"
imgPrinter.Attributes("OnMouseOut") = "javascript:window.status='';"
 
Back
Top