View Full Version : Redirecting External Links to Dynamic iFrame

01-25-2010, 03:56 AM
- Disclaimer 1: I am not a programmer, just a curious designer, so please take that into consideration in your replies.
- Disclaimer 2: Despite all advices against it, I couldn't find a better solution to my website than using iFrame
- Disclaimer 3: Before asking for help, I researched *several* forums and although I found people discussing similar issues, I was not successful at adapting their solutions to my needs.


I need your help implementing a method to intercept and redirect external links to a dynamic iframe. By "dynamic" iframe I mean an iframe whose SRC would be filled up in accordance to the external URL being intercepted and that it would resize its HEIGHT accordingly in order to avoid scroll bars.
The function for resizing the iframe id="child" is already correctly implemented like so:

<script language="JavaScript">
function calcHeight()
//find the height of the internal page
var the_height=
//change the height of the iframe

and the call

<iframe src="/main/index.php" width="100%" onLoad="calcHeight();" height="1" marginheight="0" marginwidth="0" scrolling="no" frameborder="0" id="child">

This what I have going on:

- index.html => contains some content and the iframe id="child"
- childpage1[...N].php => several PHP pages which I do not want to show up outside of the parent "index.html". These pages use clean URLs from CMS such as "http://mydomain.com/pages/this-is-a-child-page/". Users might click on external links from search engines, for instance, about an specific page such as "http://mydomain.com/pages/this-is-child-page-7/" which obviously would load the page "orphaned", outside "index.html" and that is exactly what I am trying to avoid.

Based on what I have researched so far, the best way (please, correct me if I'm wrong) to deal with this would be implementing a test condition on the header of the PHP child pages to verify if they are on "top" or not (if they are already inside the "parent" object "index.html"). If FALSE, the page would load normally, if TRUE, a variable should be created to store the URL of the requested page and passed through the link to the page "index.html" which would be immediately called.

In "index.html" there would be a script to collect the variable sent through the link (something like "http://mydomain.com/?var=http://mydomain.com/pages/this-is-child-page-7/") and break the text string apart, store a portion of PATHNAME (in this case, "/pages/this-is-child-page-7/) and use it to replace the current SRC of iframe id="child". Probably, there would have to be another testing function in this script to compare the variable passed from the "orphaned" PHP page against the current value of SRC in iframe id="child" to determine if any action is actually required.

This "replacement" function would be called onLoad and if tested true would run and refresh the page with the proper value in the iframe SRC.
All this should be accomplished while still making the iframe HEIGHT dynamically adjustable and show a "clean" URL in the browser, such as "http://mydomain.com".

The potential issues I foresee is an infinite loop due to two onLoad queries (one for SRC, another for HEIGHT) in the parent and child objects, which might required a merge into a single script.

As you can tell, I have an idea of what needs to be done but not a clue on how to get it done. Any help would be greatly appreciated.


01-26-2010, 03:23 AM


01-26-2010, 03:29 AM
I don't understand the problem... I'm sorry. =/

01-26-2010, 05:27 PM
Let me try to explain a little further then.

The reason is that the parent page is a static page whose iframe will alternate between two different CMS engines, basically switching between two websites which are identically styled thus making the switch transparent to the user.

To make this clearer, let's say i have two databases, one for joomla and another one for drupal, so this is how i need the external clicks to behave:

- user clicks "http://mydomain.com/joomla/this-is-page-7", he gets sent to "http://mydomain.com/index.html" with the iframe containing "/joomla/this-is-page-7/".

- user clicks "http://mydomain.com/drupal/this-is-page-10", he gets sent to "http://mydomain.com/index.html" with the iframe containing "/drupal/this-is-page-10/".

Again, this behavior should be accompanied by proper resizing of the iframe's HEIGHT and keeping a clear URL in the browser. The clean URL is desirable but is the least important aspect of this whole enchilada.

I would like to refer you to this link (http://www.dynamicdrive.com/forums/archive/index.php/t-8567.html) which I studied and tried to implement to my needs without success, as I am sure you will read it with different eyes than mine.

I believe I need to share with you the reason why I am using an iframe to begin with.

The index.html holds a banner containing a slow, long and cyclic animation. If I were to put this banner in the header of the index.php page currently being loaded inside the iframe (avoiding the use of an iframe altogether, just having index.php as the top object), every time the user navigated by clicking in the menu options, the whole page would reload, forcing the animation to restart, which is *unacceptable*. The solution I found was creating a static page to hold the banner and maintain its fluidity while the users can navigate anywhere within the website without causing interruptions.

I hope I have made matters clearer instead of more confusing. Thanks,

01-27-2010, 01:07 AM
You would give the "a" a target of the name of the iframe. Example:

<a href="http://google.com" target="a">Hi</a>
<iframe width="100%" height="100%" src="http://yahoo.com" name="a"/>

01-27-2010, 08:34 PM
Thank you, Nile, I wish it were that simple...

If you could follow the discussion here (http://www.codingforums.com/showthread.php?p=915407#post915407), maybe you'll get what i mean.


01-27-2010, 10:21 PM
Sorry, I still don't understand.

01-27-2010, 11:24 PM
I posted a thread on something similar HERE (http://www.dynamicdrive.com/forums/blog.php?bt=64), except that I don't use PHP.
I think you're looking for something like it. There's a demo.
The advantage of what you're looking for is that external scripts and styles won't get lost during 'inclusion'.
Arie Molendijk.