Solved

check the parent frame's name and make decisions based on it

Posted on 2010-09-20
12
408 Views
Last Modified: 2012-06-22
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

 
0
Comment
Question by:Steynsk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 33715401
Maybe a better design strategy would be to pass a GET string to the script that runs in the inner frame.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 33715414
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>

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 33715420
Here is the other part of the demonstration script.

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;
}

Open in new window

0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33715531
0
 
LVL 1

Author Comment

by:Steynsk
ID: 33715643
@ 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..
0
 
LVL 1

Author Comment

by:Steynsk
ID: 33715694
I more think in this direction:

if(parent.frames !=="parent.htm")
  parent.frames.location="parent.htm";

Sory my javascript knowlige is small
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33715705
it should be

if(parent.framename.location !=="parent.htm")
  parent.framename.location="parent.htm";

where framename is the name of the frame you are trying to access.
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33715754
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
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33715773
You may use :


      var url = parent.location.href;
      var str = url.lastIndexOf("/") + 1;
      var pageName = url.substr(str);

      if(pageName.indexOf("parent.htm") == 0 ) {
            parent.framename.location="parent.htm"
      }
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 33716672
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
0
 
LVL 1

Author Closing Comment

by:Steynsk
ID: 33765851
thanks
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33765869
You're welcome! Thanks for the points!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question