Steynsk
asked on
check the parent frame's name and make decisions based on it
Hi Expert,
Is it possible to retrieve the name of a parent frame and make decisions based on that value?
Let's say I put code in the child frame that checks the name of the parent and if it is not "parent.htm" it reloads the page within in the “parent.htm” parent page?
I know I should no longer use frames but in this old site I just need to.
Thanks,
Gurbe
Is it possible to retrieve the name of a parent frame and make decisions based on that value?
Let's say I put code in the child frame that checks the name of the parent and if it is not "parent.htm" it reloads the page within in the “parent.htm” parent page?
I know I should no longer use frames but in this old site I just need to.
Thanks,
Gurbe
Maybe a better design strategy would be to pass a GET string to the script that runs in the inner frame.
IIRC, this should work, too.
<?php // RAY_timestamp_handshake_parent.php
error_reporting(E_ALL);
// DEMONSTRATE HOW TO USE A HANDSHAKE BETWEEN A MAIN WEB PAGE AND AN IFRAME.
// IF THE IFRAME IS NOT CALLED FROM THE MAIN WEB PAGE, IT WILL REDIRECT TO
// THE MAIN WEB PAGE. THE STRATEGY USES A TIMESTAMP TWO SECONDS IN THE FUTURE
// AS A KEY TO UNLOCK THE IFRAME.
// ALWAYS START THE SESSION UNCONDITIONALLY ON EVERY PAGE
session_start();
// SET THE WINDOW OF OPPORTUNITY
$_SESSION["tm"] = time() + 2;
?>
<html>
<head><title>PARENT</title></head>
<body>
<p>THIS IS THE PARENT PAGE</p>
<p>HERE IS THE IFRAME, RIGHT BELOW</p>
<iframe src="/RAY_timestamp_handshake_child.php"></iframe>
<p>THAT IS THE IFRAME, UP THERE</p>
</body>
</html>
Here is the other part of the demonstration script.
HTH, ~Ray
HTH, ~Ray
<?php // RAY_timestamp_handshake_child.php
error_reporting(E_ALL);
// THIS IS THE CHILD SCRIPT IN THE IFRAME
// ALWAYS START THE SESSION UNCONDITIONALLY ON EVERY PAGE
session_start();
// IF THE TIMESTAMP IS FILLED IN
if (isset($_SESSION["tm"]))
{
// IF THE TIMESTAMP IS STILL IN THE RANGE
if ($_SESSION["tm"] > time())
{
// CREATE THE IFRAME OUTPUT HERE
echo "HELLO FROM THE IFRAME<br/>" . PHP_EOL;
var_dump($_SESSION);
// CLEAR THE TIMESTAMP
unset($_SESSION["tm"]);
}
else
{
// CLEAR THE TIMESTAMP
unset($_SESSION["tm"]);
// GO BACK TO THE PARENT
header("Location: /RAY_timestamp_handshake_parent.php");
exit;
}
}
// IF THE TIMESTAMP IS NOT FILLED IN
else
{
// GO BACK TO THE PARENT
header("Location: /RAY_timestamp_handshake_parent.php");
exit;
}
ASKER
@ Ray,
My question is about good old fesion frames not Iframes. And sorry I don't want to write info to session variables. Can't this be done in plane javascript?
@ddsh79
That has nothing to do with getting the parent file name.
Sorry..
My question is about good old fesion frames not Iframes. And sorry I don't want to write info to session variables. Can't this be done in plane javascript?
@ddsh79
That has nothing to do with getting the parent file name.
Sorry..
ASKER
I more think in this direction:
if(parent.frames !=="parent.htm")
parent.frames.location="pa rent.htm";
Sory my javascript knowlige is small
if(parent.frames !=="parent.htm")
parent.frames.location="pa
Sory my javascript knowlige is small
it should be
if(parent.framename.locati on !=="parent.htm")
parent.framename.location= "parent.ht m";
where framename is the name of the frame you are trying to access.
if(parent.framename.locati
parent.framename.location=
where framename is the name of the frame you are trying to access.
if you are trying to get the url of the page itself then you can use
window.location.href
this will give you the complete url as http://www.xyz.com/parent.html
window.location.href
this will give you the complete url as http://www.xyz.com/parent.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well, stupid me. I just took a long-shot guess that you might want a PHP solution since you posted the question in the PHP Zone.
Maybe these results will help:
http://lmgtfy.com?q=Learn+JavaScript
Over and out, ~Ray
Maybe these results will help:
http://lmgtfy.com?q=Learn+JavaScript
Over and out, ~Ray
ASKER
thanks
You're welcome! Thanks for the points!