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!

Passing variable to window.open function

Status
Not open for further replies.

SteveMersereau

Technical User
Feb 6, 2002
23
0
0
GB
This is what I want...!

User clicks on an image link, a pop up window opens with a bigger version of the image. So far, so simple! The problem I'm having is passing a variable to the function to define the size of the opened window.

The code I've got is this;

Code:
<SCRIPT language=JavaScript>
<!--
function newWindow(winSource,winWidth,winHeight)
    {

    openedWindow=window.open(winSource, 'openedWin', 'width=winWidth, height=winHeight, border=0,left=100,top=100,toolbar=no,scrollbars=no,location=no,resizable=no')
     openedWindow.focus()
    }
//-->
</SCRIPT>
in the Head and

Code:
<a href=&quot;javascript:newWindow('chemistry.htm',238,395)&quot;><img src=&quot;Chemistry_a.JPG&quot; width=&quot;100&quot; height=&quot;166&quot; border=&quot;1&quot; alt=&quot;Essential Chemistry&quot;></a>
for the link. The window is opening fine but no matter how I fiddle with the quotation marks/apostrophes etc the window always opens at the same (wrong) size.

Any ideas?

Love

Steve

&quot;In the Jungle of the Senses&quot;
 
You might try resizing the window after it has been opened. That way you skip all the confusing tick and quote marks. At the end of your script just add,

openedwindow.resizeTo(winwidth,winHeight)

Roj
 
Hi,

Erm would that just not keep on resizing itself?

James
 
have you tried changing
'width=winWidth, height=winHeight, border=0,left=100,top=100,toolbar=no,scrollbars=no,location=no,resizable=no'
to
'width='+winWidth+', height='+winHeight+', border=0,left=100,top=100,toolbar=no,scrollbars=no,location=no,resizable=no'
 
No you would put that in the same function that opens the new window. That way it only runs when the page is opened.

Roj
 
Holy Cow, that was fast!

yando's solution works well; Discord's seems to work well also, although I haven't tested it fully yet.

Thousands of thanks!

Love,

Steve

&quot;Tinkerbell, and Jack the Ripper&quot;
 
There is nothing wrong with yando's way of doing things except on slower computers where the page would load at whatever size it appears at and then with a little delay the page finally resize itself.

Discord's way makes sure the page opens with the size you want it to be in the first place. Much cleaner way of doing things.

Hope this helps. Gary Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top