Centering popup windows

C

Chris Leffer

Hi.

I wrote a small routine that opens popup windows. The code works well,
but I did a small change to center the popup window and this change does
not work. I can't understand why. That's the code:

Public Shared Sub Popup(ByVal page As Page, ByVal url As String, ByVal
title As String, ByVal width As Short, ByVal height As Short, ByVal
scroll As Boolean, Optional ByVal QueryString As String = Nothing)

Dim strWindow As New StringBuilder

With strWindow
.Append("<SCRIPT LANGUAGE=javascript for=window>" &
ControlChars.NewLine)
.Append("var nTam=" & width & ";" &
ControlChars.NewLine)
.Append("var nAlt=" & height & ";" &
ControlChars.NewLine)
.Append("var nXpos = (screen.availWidth - nTam) / 2;" &
ControlChars.NewLine)
.Append("var nYpos = (screen.availHeight - nAlt) / 2;" &
ControlChars.NewLine)
.Append("window.open('" & url & QueryString & "','" &
title & "','toolbar=no,location=no,status=no,menubar=no,resizable=no,
scrollbars=" & IIf(scroll, "yes", "no") & ",width=" & width & ",height="
& height & ",top=nYpos,screenY=nYpos,left=nXpos,screenX=nXpos');")
.Append("</SCRIPT>")
End With

page.RegisterStartupScript("win", strWindow.ToString)

End Sub

I tried to create the routine to work with both IE and Netscape. When I
run the code, the window always opens at left=0 and top=0. It seems to
ignore the variables.

Can anyone help me to detect the error?

Regards,
Chris Leffer
 
B

bruce barker

in client script window.open takes a string, in this string you are passing
the parameter names not values, try

& height & ",top='+nYpos+',screenY='+nYpos+
',left='+Xpos+',screenX='+nXpos);")


-- bruce (sqlwork.com)



| Hi.
|
| I wrote a small routine that opens popup windows. The code works well,
| but I did a small change to center the popup window and this change does
| not work. I can't understand why. That's the code:
|
| Public Shared Sub Popup(ByVal page As Page, ByVal url As String, ByVal
| title As String, ByVal width As Short, ByVal height As Short, ByVal
| scroll As Boolean, Optional ByVal QueryString As String = Nothing)
|
| Dim strWindow As New StringBuilder
|
| With strWindow
| .Append("<SCRIPT LANGUAGE=javascript for=window>" &
| ControlChars.NewLine)
| .Append("var nTam=" & width & ";" &
| ControlChars.NewLine)
| .Append("var nAlt=" & height & ";" &
| ControlChars.NewLine)
| .Append("var nXpos = (screen.availWidth - nTam) / 2;" &
| ControlChars.NewLine)
| .Append("var nYpos = (screen.availHeight - nAlt) / 2;" &
| ControlChars.NewLine)
| .Append("window.open('" & url & QueryString & "','" &
| title & "','toolbar=no,location=no,status=no,menubar=no,resizable=no,
| scrollbars=" & IIf(scroll, "yes", "no") & ",width=" & width & ",height="
| & height & ",top=nYpos,screenY=nYpos,left=nXpos,screenX=nXpos');")
| .Append("</SCRIPT>")
| End With
|
| page.RegisterStartupScript("win", strWindow.ToString)
|
| End Sub
|
| I tried to create the routine to work with both IE and Netscape. When I
| run the code, the window always opens at left=0 and top=0. It seems to
| ignore the variables.
|
| Can anyone help me to detect the error?
|
| Regards,
| Chris Leffer
|
|
|
| Don't just participate in USENET...get rewarded for it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,035
Latest member
HoTaKeDai

Latest Threads

Top