javascript sending variable

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

    javascript sending variable

    Hi,

    Is there a way to send a variable to a different page that it is
    redirecting to? For example,

    <script type="text/javascript">

    var o;
    if ( (o = top)
    && (o = o.frames)
    && (o = o.bob)
    && (o = o.document)
    && (o = o.title)
    && o == "test"
    ){
    document.write( "yes")
    } else {
    document.locati on.href = "New Text Document.php "
    }
    </script>

    If it is false, I would like it to set a variable that it will send to
    the page "New Text Document.php" (that it is redirecting to). Is this
    possible?

    Dan

  • Thomas 'PointedEars' Lahn

    #2
    Re: javascript sending variable

    Dan wrote:
    [color=blue]
    > <script type="text/javascript">
    > var o;
    > if ( (o = top)
    > && (o = o.frames)
    > && (o = o.bob)
    > && (o = o.document)
    > && (o = o.title)
    > && o == "test"[/color]

    Looks like my code, although I would have spared the last assignment :)
    [color=blue]
    > ){
    > document.write( "yes")
    > } else {
    > document.locati on.href = "New Text Document.php "[/color]
    ^ ^ ^
    Err, spaces are _not_ allowed within URIs.
    [color=blue]
    > }
    > </script>
    >
    > If it is false, I would like it to set a variable that it will send to
    > the page "New Text Document.php" (that it is redirecting to). Is this
    > possible?[/color]

    Sure,

    document.locati on.href =
    "New%20Text%20D ocument.php?nam e1=value1&name2 =value2";

    (or use concatenation and escape/encodeURICompon ent.)

    In PHP, you use the $_GET superglobal (PHP >= 4.1) or
    $HTTP_GET_VARS (PHP < 4.1), with safer register_global s=off.

    I wonder why you did not use much more reliable server-side
    redirection in the first place:

    <URL:http://www.w3.org/QA/Tips/reback>


    PointedEars

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: javascript sending variable

      Thomas 'PointedEars' Lahn wrote:
      [color=blue]
      > Dan wrote:[color=green]
      >> document.locati on.href = "New Text Document.php "[/color]
      > [...]
      > document.locati on.href =
      > "New%20Text%20D ocument.php?nam e1=value1&name2 =value2";[/color]

      `document.locat ion(.href)' is deprecated long
      since, use window.location ' or just `location'.


      PointedEars

      Comment

      Working...