iFrames - need redirection help

I have a webpage that may need tro display other webpages (well html documents really) in a panel, so a wrapper using iFrame call is being used.  Its working pretty well except...

If the document in the iframe has a link to yet another place, like google, that page will come up in the iframe, as it should.  However, if the document has a link to my website then what happen is I get another version of my website inside the iFrame.

What id like to do, is have the behavior that links to mysite, are redirected to the parent window, not the iFrame window

I've tried using htaccess redirects, but they 'stay' within the iframe window

for example, I know that
http_referer will have 'htmlwrapper'  if the call is from within the iframe
but if I RewriteRule to go to mysite/test.html  - I get the entire mysite/test.html displayed within the iframe

Hope all that make sense as a problem description


allan1956Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mrcoffee365Commented:
If you name your frames, then put target="main" in the links for your own site, the page will display with your site's page as the main page.

For example:
In your frameset page:
<frame src="/myapp/outerpagename.html" name="main">

In your outerpagename.html:
<iframe name="contentFrame" src="/myapp/listpage.html">

In your listpage.html:
<a target="main" href="/myapp/anyapppage.html">Link back to home site</a>
<br/><a href="http://somedomain.com/page.html">Link to somewhere else without target = main</a>
0
allan1956Author Commented:
Hi, I understand the use of the target="_parent' and target="_top" seem to work on the few links I tested in one of the iFrame dispalyed documents ,  though I'm not sure that approach willwork for me, let me clarify some things

First the top or main web page is not a frame so <frame name=main /> isn't going to work, Im using an iFrame within just plain web page

But mostlly, the target= approach requires me to 'touch' and modify all the links in all of the html pages that show up in the iFrame.  Lets say I dont have access to those pages to add the target= call

So I desire something that doesnt touch the content inside the iFrame, but anything outside that (apache server, the code (php) displaying the main page, or javascript that would go in main page.  Some code that realizes that if it (the main page) is being opened within an iFrame, and kicks itself back up to the parent of the iFrame, if that makes sense?
0
allan1956Author Commented:
I think I found an answer
I put the following code the top/main webpage
htmlwrapper is where allt he html documents displayed int he iFrame will be
Seems to be working just fine


<script type="text/javascript">
<!--//--><![CDATA[//><!--
var parent_location = new String(parent.location);
   if ( ( top.location != location ) && parent_location.indexOf('htmlwrapper') != 0 )
     top.location.href = document.location.href;
//--><!]]>
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mrcoffee365Commented:
Okay -- you could add Javascript to your main page, detect the referer as htmlwrapper, and redirect to the page.  Something like this:

<script language="javascript" type="text/javascript">
<!--
function frameRedirect() {
      if (document.referrer.indexOf('htmlwrapper') != -1) window.location.replace('/myouterpage.html');
}
//  End -->
</script>
</head>
<body onload='frameRedirect()'>


Make sure that indexOf('htmlwrapper') can't ever be true on a normal load of the page, or this will send your page into an endless loop of redirects.
0
mrcoffee365Commented:
Oh sorry -- I was testing out the solution I posted, so I didn't see your answer.  Yours looks fine.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.