By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,490 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,490 IT Pros & Developers. It's quick & easy.

variable in window.open function

P: n/a
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>

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Lee
ro******@hotmail.com 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.

Jul 23 '05 #2

P: n/a
Lee <RE**************@cox.net> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3

P: n/a
Lasse Reichstein Nielsen wrote:
Lee <RE**************@cox.net> writes:
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
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.