Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open pop-up window with size in reference to screen size 2

Status
Not open for further replies.

kev510

Programmer
Jul 12, 2006
61
0
0
Hello everyone,

I have the below javascript function in my webpage -

function fPopupWindow()
{
vURL = "Webpage.asp"
window.open(vURL,['PopUp1'],'toolbar=no,status=no,scrollbars=no,resizable=yes,width=1025,height=1000,left=20,top=100');
}

But instead of hard-coding the width and position of the popup window, I would like them to be more dynamic. What exactly I want to do is to center the screen horizontally and then size the width so that the popup screen leaves about 30px to the left and right of the window, to the edge of the screen.

Thank you for your help in advance.
Kevin
 
You need to use "screen.availWidth" and "screen.availHeight" to get the available screen resolution (after desktop toolbars, etc, have been taken into account).

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks for your suggestion.
I tried the following -

function fPopupWindow()
{
var aw = screen.availWidth - 40
vURL = "Webpage.asp"
window.open(vURL,['PopUp1'],'toolbar=no,status=no,scrollbars=no,resizable=yes,width="+aw+",height=1000,left=20,top=100');
}

but it seems it's not working. The screen pops up with a windows-set default width... Any suggestions?
 
You started the string with a single quote (') but tried to terminate the string with a double quote (").

Change the double quotes to single quotes:
Code:
'toolbar=no,status=no,scrollbars=no,resizable=yes,width=[!]'[/!]+aw+[!]'[/!],height=1000,left=20,top=100'

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
What is the crazy "[]" syntax around the second param? It should be a string, not an array with 1 item.

Try using correct types for your parameters and see if the code works.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thank you thank you thank you billy ray's son and kaht.

Kaht, you were right about the double quotes. Without the double quotes, the javascript works!

Billy, I will not be using those crazy []'s from now on. I am learning new things every day... Thanks for that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top