variable in window.open function

R

robburne

Can anyone help with my javascript code please?

I have a button which when pressed calls a function named 'popjack'
which pops up a new browser window. The function is called with a
paramter 'printflag' and I want to assign the value of this to a
variable 'var1' in the url of the browser window to be opened.

Here is my code below, but 'var1=' part is wrong, can anyone help
please. Many thanks.

Rob.

<script language="JavaScript">

function popjack(printflag){

window.open('myfile.php?var1=printflag','popjack1',
'toolbar=no,location=no,width=650,height=534');
}

</script>

<button class=button onClick="JavaScript: popjack(1)"> Print
Waybill</button>
 
L

Lee

(e-mail address removed) said:
Can anyone help with my javascript code please?

I have a button which when pressed calls a function named 'popjack'
which pops up a new browser window. The function is called with a
paramter 'printflag' and I want to assign the value of this to a
variable 'var1' in the url of the browser window to be opened.

Here is my code below, but 'var1=' part is wrong, can anyone help
please. Many thanks.

Rob.

<script language="JavaScript">

function popjack(printflag){

window.open('myfile.php?var1=printflag','popjack1',
'toolbar=no,location=no,width=650,height=534');

window.open('myfile.php?var1='+printflag,'popjack1',
'width=650,height=534,resizeable');

toolbar and location are "no" by default if you specify
any attributes. Popups shold always be resizable because
you don't know what the user might have done with font size.
 
L

Lasse Reichstein Nielsen

Lee said:
window.open('myfile.php?var1='+printflag,'popjack1',
'width=650,height=534,resizeable');

This works if the string passed as "printflag" contains only
characters valid in a URL. Otherwise, it would be safest
to escape the string. For a URL simulating a GET request,
that means using the "escape" function, and also turning
spaces into plusses (that's what posting a form would do):

printflag = escape(printflag).replace(/[ ]/g,"+");
toolbar and location are "no" by default if you specify
any attributes. Popups shold always be resizable because
you don't know what the user might have done with font size.

Hear, hear!
/L
 
T

Thomas 'PointedEars' Lahn

Lasse said:
Lee said:
window.open('myfile.php?var1='+printflag,'popjack1',
'width=650,height=534,resizeable');

This works if the string passed as "printflag" contains only
characters valid in a URL. Otherwise, it would be safest
to escape the string. For a URL simulating a GET request,
that means using the "escape" function, and also turning
spaces into plusses (that's what posting a form would do):

printflag = escape(printflag).replace(/[ ]/g,"+");

This will not work as supposed, as the spaces are already
converted to `%20' by escape(). The following should work:

printflag = escape(printflag).replace(/%20/g,"+");

Or consider this:

printflag = escape(printflag.replace(/ /g, "+"));

I also wonder why you used a character class only for a
space character.


PointedEars
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top