470,586 Members | 1,346 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,586 developers. It's quick & easy.

How To Pass Parameters in URL for Javascript Refresh?

DCB
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.location.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.html 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.location.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.
Jul 23 '05 #1
3 31504
DCB wrote:
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.location.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.html 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.location.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.


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=somepageyoudonotwantmetosee

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 <gw*****@agricoreunited.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
Jul 23 '05 #2
DCB
Yeah, it's really weird. It appears to me that the location.replace
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.replace 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 <gw*****@agricoreunited.com> wrote in message news:<40***************@agricoreunited.com>...
DCB wrote:
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.location.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.html 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.location.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.


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=somepageyoudonotwantmetosee

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 <gw*****@agricoreunited.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

Jul 23 '05 #3
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">alert(window.location.search);</script>
<form><input type="button" value="Click to see the value of redir"
onclick="window.location.replace(window.location.h ref + '?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.replace(window.location.h ref + '?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:
Yeah, it's really weird. It appears to me that the location.replace
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.replace 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 <gw*****@agricoreunited.com> wrote in message news:<40***************@agricoreunited.com>...
DCB wrote:
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.location.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.html 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.location.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.


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=somepageyoudonotwantmetosee

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 <gw*****@agricoreunited.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
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Al Franz | last post: by
5 posts views Thread by Ben | last post: by
6 posts views Thread by Woody Splawn | last post: by
3 posts views Thread by Wang Xiaoning | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.