variable in window.open function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robburne@hotmail.com

    #1

    variable in window.open function

    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="JavaS cript">

    function popjack(printfl ag){

    window.open('my file.php?var1=p rintflag','popj ack1',
    'toolbar=no,loc ation=no,width= 650,height=534' );
    }

    </script>

    <button class=button onClick="JavaSc ript: popjack(1)"> Print
    Waybill</button>

  • Lee

    #2
    Re: variable in window.open function

    robburne@hotmai l.com said:[color=blue]
    >
    >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="JavaS cript">
    >
    >function popjack(printfl ag){
    >
    >window.open('m yfile.php?var1= printflag','pop jack1',
    >'toolbar=no,lo cation=no,width =650,height=534 ');[/color]

    window.open('my file.php?var1=' +printflag,'pop jack1',
    'width=650,heig ht=534,resizeab le');

    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.

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: variable in window.open function

      Lee <REM0VElbspamtr ap@cox.net> writes:
      [color=blue]
      > window.open('my file.php?var1=' +printflag,'pop jack1',
      > 'width=650,heig ht=534,resizeab le');[/color]

      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(printfla g).replace(/[ ]/g,"+");
      [color=blue]
      > 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.[/color]

      Hear, hear!
      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: variable in window.open function

        Lasse Reichstein Nielsen wrote:
        [color=blue]
        > Lee <REM0VElbspamtr ap@cox.net> writes:[color=green]
        >> window.open('my file.php?var1=' +printflag,'pop jack1',
        >> 'width=650,heig ht=534,resizeab le');[/color]
        >
        > 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(printfla g).replace(/[ ]/g,"+");[/color]

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

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

        Or consider this:

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

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


        PointedEars

        Comment

        Working...