View Full Version : Redirect Iframe when loaded directly

09-08-2008, 09:00 PM
I'm using an Iframe on 1 page, without problems, however I like to built in some "security", to make sure the user sees what I want them to see....
When user goes directly to the iframe source, I like to have that page redirect to the page that contains the Iframe,

page 123.xxx contains the iframe. In this iframe it loads page 456.xxx

Now when a user goes directly to 456.xx, I like that page to redirect automatically, so 123.xxx will be loaded.
As some users might not be able to view iframes, I show the user a link that I have in the iframe code, to "click here" and this will open the page 456.xxx in a new window.

I was maybe thinking of using the referral link...
Something like: If referral link is 123.xxx, show content, else redirect to 123.xxx
Anyone ideas on how to accomplish this?

09-08-2008, 10:41 PM
With javascript placed in 456.xxx this works:

<script language="JavaScript"><!--
var ref = document.referrer;
if (ref.indexOf('www.myurl.com') != -1)
window.location.href = 'http://www.myurl.com/123.xxx';