How To Pass Parameters in URL for Javascript Refresh?

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

    How To Pass Parameters in URL for Javascript Refresh?

    Hello.

    I have an easy question, likely, that has me in a headspin. I have an
    include file to a frames based site that basically forces frames on
    the end user if they visit the site and hit a non-frames created
    page...

    Simply, it is:

    if (parent != self)
    self.parent.loc ation.replace("/");

    However, now I would like to force an inner frame to populate based on
    what frame someone was redirected from the include (above). So, if I
    visit http://domain/frame/innerframe_3.html, then I want to redirect
    to the above, but pass in /frame/innerframe_3.ht ml to be included as a
    URL parameter for an inner frame to be populated.

    When I modify this link to:

    if (parent != self)
    self.parent.loc ation.replace("/index.php?redir =" & location.href);

    Then, the replaced location doesn't seem to recognize the ?redir=
    portion of the new location.

    Is there a different way to do this? I can't use a META tag because I
    want the TARGET to be _TOP, basically.

    Thanks if anyone has a clue.
    D.
  • Grant Wagner

    #2
    Re: How To Pass Parameters in URL for Javascript Refresh?

    DCB wrote:
    [color=blue]
    > Hello.
    >
    > I have an easy question, likely, that has me in a headspin. I have an
    > include file to a frames based site that basically forces frames on
    > the end user if they visit the site and hit a non-frames created
    > page...
    >
    > Simply, it is:
    >
    > if (parent != self)
    > self.parent.loc ation.replace("/");
    >
    > However, now I would like to force an inner frame to populate based on
    > what frame someone was redirected from the include (above). So, if I
    > visit http://domain/frame/innerframe_3.html, then I want to redirect
    > to the above, but pass in /frame/innerframe_3.ht ml to be included as a
    > URL parameter for an inner frame to be populated.
    >
    > When I modify this link to:
    >
    > if (parent != self)
    > self.parent.loc ation.replace("/index.php?redir =" & location.href);
    >
    > Then, the replaced location doesn't seem to recognize the ?redir=
    > portion of the new location.
    >
    > Is there a different way to do this? I can't use a META tag because I
    > want the TARGET to be _TOP, basically.
    >
    > Thanks if anyone has a clue.
    > D.[/color]

    You should probably be using: locationreplace ('/index.php?redir =' +
    escape(location .href)); to make sure any characters that don't belong in the
    query string are encoded first.

    For the replaced location to "recognize" the ?redir= portion of the new
    location, you have to read it and write the <frame> tag in index.php based on
    it's contents. This would be done using PHP:

    <?php
    $redir = $_GET['redir'];
    if (!$redir) {
    $redir = '/somedefault.php ';
    }
    ?>
    <frameset>
    ....
    <frame src="<?php echo $redir ?>" ... >
    ....
    </frameset>

    You really should probably do more validation on $_GET['redir'] then I've
    shown, since I could load any page on your site using
    /index.php?redir =somepageyoudon otwantmetosee

    If the above isn't working, start simple:

    <?php
    $redir = $_GET['redir'];
    echo $redir;
    ?>
    <!--
    <frameset>
    ....
    </frameset>
    -->

    does it output the value you passed on ?redir= ?

    --
    | Grant Wagner <gwagner@agrico reunited.com>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *


    * Internet Explorer DOM Reference available at:
    *
    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    * http://www.mozilla.org/docs/web-deve...upgrade_2.html


    Comment

    • DCB

      #3
      Re: How To Pass Parameters in URL for Javascript Refresh?

      Yeah, it's really weird. It appears to me that the location.replac e
      ignores parameters passed into it. When I go directly to the url and
      type the parameters into the URL...

      http://www...com/index.php?redir=/news/index.html

      then it works perfect.

      However, if I go to

      http://www...com/news/index.html

      It will redirect to the framebuilder correctly and build the frames,
      but the ?redir=/news/index.html is totally ignored... including if I
      simply look for the get value in PHP and write it to the page alone.

      Does location.replac e ignore any GET/URL parameters?

      I'm working on setting a cookie instead, but this seems like a bit of
      overkill.

      If anyone else has struggled with this, I'd appreciate your insight.

      Thanks, Greg!

      - Derek.



      Grant Wagner <gwagner@agrico reunited.com> wrote in message news:<40CDF20B. A87772F9@agrico reunited.com>.. .[color=blue]
      > DCB wrote:
      >[color=green]
      > > Hello.
      > >
      > > I have an easy question, likely, that has me in a headspin. I have an
      > > include file to a frames based site that basically forces frames on
      > > the end user if they visit the site and hit a non-frames created
      > > page...
      > >
      > > Simply, it is:
      > >
      > > if (parent != self)
      > > self.parent.loc ation.replace("/");
      > >
      > > However, now I would like to force an inner frame to populate based on
      > > what frame someone was redirected from the include (above). So, if I
      > > visit http://domain/frame/innerframe_3.html, then I want to redirect
      > > to the above, but pass in /frame/innerframe_3.ht ml to be included as a
      > > URL parameter for an inner frame to be populated.
      > >
      > > When I modify this link to:
      > >
      > > if (parent != self)
      > > self.parent.loc ation.replace("/index.php?redir =" & location.href);
      > >
      > > Then, the replaced location doesn't seem to recognize the ?redir=
      > > portion of the new location.
      > >
      > > Is there a different way to do this? I can't use a META tag because I
      > > want the TARGET to be _TOP, basically.
      > >
      > > Thanks if anyone has a clue.
      > > D.[/color]
      >
      > You should probably be using: locationreplace ('/index.php?redir =' +
      > escape(location .href)); to make sure any characters that don't belong in the
      > query string are encoded first.
      >
      > For the replaced location to "recognize" the ?redir= portion of the new
      > location, you have to read it and write the <frame> tag in index.php based on
      > it's contents. This would be done using PHP:
      >
      > <?php
      > $redir = $_GET['redir'];
      > if (!$redir) {
      > $redir = '/somedefault.php ';
      > }
      > ?>
      > <frameset>
      > ...
      > <frame src="<?php echo $redir ?>" ... >
      > ...
      > </frameset>
      >
      > You really should probably do more validation on $_GET['redir'] then I've
      > shown, since I could load any page on your site using
      > /index.php?redir =somepageyoudon otwantmetosee
      >
      > If the above isn't working, start simple:
      >
      > <?php
      > $redir = $_GET['redir'];
      > echo $redir;
      > ?>
      > <!--
      > <frameset>
      > ...
      > </frameset>
      > -->
      >
      > does it output the value you passed on ?redir= ?
      >
      > --
      > | Grant Wagner <gwagner@agrico reunited.com>
      >
      > * Client-side Javascript and Netscape 4 DOM Reference available at:
      > *
      > http://devedge.netscape.com/library/...ce/frames.html
      >
      > * Internet Explorer DOM Reference available at:
      > *
      > http://msdn.microsoft.com/workshop/a...ence_entry.asp
      >
      > * Netscape 6/7 DOM Reference available at:
      > * http://www.mozilla.org/docs/dom/domref/
      > * Tips for upgrading JavaScript for Netscape 7 / Mozilla
      > * http://www.mozilla.org/docs/web-deve...upgrade_2.html[/color]

      Comment

      • Grant Wagner

        #4
        Re: How To Pass Parameters in URL for Javascript Refresh?

        A quick test demonstrates that window.location .replace() does indeed pass the query string as written to the
        page being loaded:

        <body>
        <script type="text/javascript">ale rt(window.locat ion.search);</script>
        <form><input type="button" value="Click to see the value of redir"
        onclick="window .location.repla ce(window.locat ion.href + '?redir=this/is/a/test');">
        </form></body>

        I'd suggest you put together a similar simple page for PHP to demonstrate to yourself that the query string
        is, in fact, arriving intact:

        <body>
        <?php echo $_GET['redir']; ?>
        <form><input type="button" value="Click to see the value of redir"
        onclick="window .location.repla ce(window.locat ion.href + '?redir=this/is/a/test');">
        </form></body>

        As well, try replacing the call to window.location .replace() with alert() _without making any other changes_:

        <input type="button"
        onclick="alert( window.location .href + '?redir=this/is/a/test');">

        This will allow you to verify that the URI to the page is being created the way you think it is. Do what I
        suggested initially (and demonstrated in my test case), simply echo the value of $_GET['redir'] in index.php,
        ensure it's what you think it should be.

        DCB wrote:
        [color=blue]
        > Yeah, it's really weird. It appears to me that the location.replac e
        > ignores parameters passed into it. When I go directly to the url and
        > type the parameters into the URL...
        >
        > http://www...com/index.php?redir=/news/index.html
        >
        > then it works perfect.
        >
        > However, if I go to
        >
        > http://www...com/news/index.html
        >
        > It will redirect to the framebuilder correctly and build the frames,
        > but the ?redir=/news/index.html is totally ignored... including if I
        > simply look for the get value in PHP and write it to the page alone.
        >
        > Does location.replac e ignore any GET/URL parameters?
        >
        > I'm working on setting a cookie instead, but this seems like a bit of
        > overkill.
        >
        > If anyone else has struggled with this, I'd appreciate your insight.
        >
        > Thanks, Greg!
        >
        > - Derek.
        >
        > Grant Wagner <gwagner@agrico reunited.com> wrote in message news:<40CDF20B. A87772F9@agrico reunited.com>.. .[color=green]
        > > DCB wrote:
        > >[color=darkred]
        > > > Hello.
        > > >
        > > > I have an easy question, likely, that has me in a headspin. I have an
        > > > include file to a frames based site that basically forces frames on
        > > > the end user if they visit the site and hit a non-frames created
        > > > page...
        > > >
        > > > Simply, it is:
        > > >
        > > > if (parent != self)
        > > > self.parent.loc ation.replace("/");
        > > >
        > > > However, now I would like to force an inner frame to populate based on
        > > > what frame someone was redirected from the include (above). So, if I
        > > > visit http://domain/frame/innerframe_3.html, then I want to redirect
        > > > to the above, but pass in /frame/innerframe_3.ht ml to be included as a
        > > > URL parameter for an inner frame to be populated.
        > > >
        > > > When I modify this link to:
        > > >
        > > > if (parent != self)
        > > > self.parent.loc ation.replace("/index.php?redir =" & location.href);
        > > >
        > > > Then, the replaced location doesn't seem to recognize the ?redir=
        > > > portion of the new location.
        > > >
        > > > Is there a different way to do this? I can't use a META tag because I
        > > > want the TARGET to be _TOP, basically.
        > > >
        > > > Thanks if anyone has a clue.
        > > > D.[/color]
        > >
        > > You should probably be using: locationreplace ('/index.php?redir =' +
        > > escape(location .href)); to make sure any characters that don't belong in the
        > > query string are encoded first.
        > >
        > > For the replaced location to "recognize" the ?redir= portion of the new
        > > location, you have to read it and write the <frame> tag in index.php based on
        > > it's contents. This would be done using PHP:
        > >
        > > <?php
        > > $redir = $_GET['redir'];
        > > if (!$redir) {
        > > $redir = '/somedefault.php ';
        > > }
        > > ?>
        > > <frameset>
        > > ...
        > > <frame src="<?php echo $redir ?>" ... >
        > > ...
        > > </frameset>
        > >
        > > You really should probably do more validation on $_GET['redir'] then I've
        > > shown, since I could load any page on your site using
        > > /index.php?redir =somepageyoudon otwantmetosee
        > >
        > > If the above isn't working, start simple:
        > >
        > > <?php
        > > $redir = $_GET['redir'];
        > > echo $redir;
        > > ?>
        > > <!--
        > > <frameset>
        > > ...
        > > </frameset>
        > > -->
        > >
        > > does it output the value you passed on ?redir= ?[/color][/color]

        --
        | Grant Wagner <gwagner@agrico reunited.com>

        * Client-side Javascript and Netscape 4 DOM Reference available at:
        * http://devedge.netscape.com/library/...ce/frames.html
        * Internet Explorer DOM Reference available at:
        * http://msdn.microsoft.com/workshop/a...ence_entry.asp
        * Netscape 6/7 DOM Reference available at:
        * http://www.mozilla.org/docs/dom/domref/
        * Tips for upgrading JavaScript for Netscape 7 / Mozilla
        * http://www.mozilla.org/docs/web-deve...upgrade_2.html


        Comment

        Working...