Passing text string to a new window?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • johkar

    #1

    Passing text string to a new window?

    Would there ever be any problems with the following script depending
    on what type of characters are in the text string? I am appending the
    value of hidden form field to the query string.

    //Assume JavaScript enabled browsers and popups allowed.
    //Function to open the window
    function openWin(elm){
    var nHeight = 250;
    var nWidth = 250;
    var nXpos = (screen.availWi dth - nWidth) / 2;
    var nYpos = (screen.availHe ight - nHeight) / 2;
    var desc=document.m yForm.elements[elm].value;
    var statusPopup = window.open('de scription.htm?d esc=' +
    desc,'popupWin' ,'top=' + nYpos + ',left=' + nXpos + ',screenY=' +
    nYpos + ',screenX=' + nXpos + ',height=' + nHeight + ',width=' +
    nWidth + 'location=no,me nubar=no,resiza ble=no,scrollba rs=no,statusbar =no,toolbar=no' );
    }
    <!-- Link example to call the function and hidden field -->
    <a href="javascrip t:openWin('long desc2')">Descri ption</a>
    <input type="hidden" name="longdesc2 " value="This is some text of Joe
    Cool's & Jane Doe's." />

    The is the script in the new window.

    <html>
    <head>
    <title>Untitl ed Document</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    </head>

    <body bgcolor="#FFFFF F" text="#000000">
    <script language="javas cript" type="text/javascript">
    var description=loc ation.href.spli t('desc=');
    if(description[1])
    document.write( description[1].replace(/%20/g," "));
    </script>
    </body>
    </html>
  • kaeli

    #2
    Re: Passing text string to a new window?

    In article <e5daa16c.04103 01253.2acbda4@p osting.google.c om>,
    nosendjunk@msn. com enlightened us with...[color=blue]
    > Would there ever be any problems with the following script depending
    > on what type of characters are in the text string?[/color]

    Yes. You have to URL encode any value you send IF you're forming the URL
    yourself instead of using GET for a form.
    The ampersand would be a very big problem. It's a field separator for form
    values.

    If you use a form and use GET, it automatically encodes the values and puts
    them in the URL. I find this way to be the safest and easiest way to handle
    querystring params with unknown values, myself.
    You could just open a new window and set that as the target to a form and
    submit the form onclick instead of what you're currently doing.

    HTH

    --
    --
    ~kaeli~
    To steal ideas from one person is plagiarism; to steal from
    many is research.



    Comment

    • johkar

      #3
      Re: Passing text string to a new window?

      Thanks for the insights.

      John

      Comment

      Working...