Closed Thread Icon

Topic awaiting preservation: problems with writing variable in windowopen code Pages that link to <a href="https://ozoneasylum.com/backlink?for=8253" title="Pages that link to Topic awaiting preservation: problems with writing variable in windowopen code" rel="nofollow" >Topic awaiting preservation: problems with writing variable in windowopen code\

 
Author Thread
GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 08-06-2002 18:01

this is the code that im using to pop up a new window:

popupWin = window.open(url,name,"width=wid,height=hei,left=50,screenX=50,top=50,screenY=50");

the width and height should be variable too. but it doesnt work with this code, it only works if i type in the values manually like:

popupWin = window.open(url,name,"width=700,height=500,left=50,screenX=50,top=50,screenY=50");

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 08-06-2002 18:04

JavaScript doesn't parse strings (like PHP, for example), so you'll have to write your code like this:

popupWin = window.open(url,name,"width="+wid+",height="+"hei"+",left=50,screenX=50,top=50,screenY=50");


Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-06-2002 18:06

Remember that that string isn't javascript code; it's a string, a piece of data. If you want to put values in there that you don't know ahead of time, then you must do it like this:

popupWin = window.open(url,name,"width=" + wid + ",height=" + hei + ",left=50,screenX=50,top=50,screenY=50");

[edit: rrrrrrr!]

[This message has been edited by Slime (edited 08-06-2002).]

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 08-06-2002 23:06

ahhh. of course!
stupid me! i should have known that!

thanks guys!

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 08-07-2002 10:25

Grumble, you can still do that:

code:
<script language="JavaScript">
<!--
function jsprintf()
{
// v0.0.1, 06/09/01, 01:26:42PM
str = arguments[0]; j = 1;
while ( (idx = str.indexOf("%s")) != -1)
str = str.substr(0, idx) + arguments[j++] + str.substr(idx+2);
return str;
}
//-->
</script>



use this now as:

popupWin = window.open(url,name,jsprintf("width=%s,height=%s,left=50,screenX=50,top=50,screenY=50", wid, hei));

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 08-08-2002 13:37

ah, hehe a JS implementation of C's printf.

« BackwardsOnwards »

Show Forum Drop Down Menu