NOTE: In the examples below, I have used [] brackets
where the normal <> brackets appear. To use the code, replace the [] brackets
with the normal <> brackets. The actual Window.Open function below is shown on 3
lines that should only be one line in the final implementation.
You can open a javascript window in your ASPX application in three easy steps
:
1. In the .aspx page, insert your button control.
[asp:Button id="btnWn" runat="server" Text="Open Java Window"][/asp:Button]
2. Also in the .aspx page, include a javascript window function. The one that appears centers the window based on w=width and h=height parameters.
[script language="javascript"]
[!--
function CenterWindow(url,w, h)
{
if (document.all)var xMax = screen.width, yMax = screen.height;
else
{
if (document.layers) var xMax = window.outerWidth, yMax = window.outerHeight;
else var xMax = 640, yMax=480;
}
if (w>xMax) w = xMax * .9;
if (h>yMax) h = yMax * .9;
var l = (xMax - w)/2, t = (yMax-h)/2;
handle_PUH = window.open(url,"About",'screenX='+l+',left='+l+',
screenY='+t+',top='+t+',toolbar=0,location=0,directories=0,status=0,
menubar=0,scrollbars=2,resizable=1,fullscreen=0,width='+w+',height='+h);
}
// End -->
[/script]
3. In the Page_Init function of the .aspx.cs code behind page, add the followin code.
btnWn.Attributes.Add("onclick","javascript:CenterWindow('DnYzWindow.aspx',500,500)" );
A sample implementation can be found at http://dn.yyyz.net/DnYzTest01.aspx - look for the button named 'Java Window 2'.
Top 