View Full Version : Linking 2 sites with seperate IFRAMES

08-09-2012, 09:49 PM
As part of a my new job within my company, I inherited maintenance of a bunch of sites that were built using IFRAMES. This was a great solution back when they were built (goodness knows how long ago) but now it's a real pain when there are so many better development solutions.

Until I can get the go-ahead to re-build the sites in a more user-friendly manner, I'm stuck managing the sites on my own.

What I need to do, and can't figure out for the life of me how, is to create a link that opens a particular page in it's correct parent IFRAME window, even when the other site is down.

For instance, I have a link on Site A for a page that would normally dispaly in an IFRAME on Site B. When I create a link to that page, I can set it, of course, to open in Site A's IFRAME or on it's own (without Site B's "parent" IFRAME) in the current window or a new window. What I'd really like to do, though, is open the page in SITE B's IFRAME. What I mean by this is that when you're viewing Site A, you click on the link, and Site B's "Parent" window opens up displaying the correct information in Site B's IFRAME window (regardless of whether or not Site B is already open or not).

Goodness, this is harder to describe in text than I thought. I hope I'm making sense. Please let me know if you have any questions. Any ideas how I might get this accomplished?

08-09-2012, 10:18 PM
I believe this needs to use a little bit of JavaScript. The page to display in the 2nd iframe is passed in the link from the 1st page. A function in the 2nd page extracts this information and uses this to display the correct content in the iframe.

<a href="pageb.htm?iframepage1.html">Iframe page 1</a><br>
<a href="pageb.htm?iframepage2.html">Iframe page 2</a><br>

<!DOCTYPE html>
<title>Document Title</title>
<script type="text/javascript">
function loadIframe() {
if (location.search.length > 0) {
url = unencodeURIComponent(location.search.substring(1));
document.getElementById("myiframe").location = url;
} else {
url = "defaultpage.html";


<iframe name="myiframe" id="myiframe" src=""></iframe>

It won't work if site B is down (of course..) and it would be easy (without further code) for someone to hijack the link so that it displays different content in the iframe.

08-09-2012, 11:27 PM
Thanks for the Javascript solution, I'll give it a whirl.

I'm not concerned with someone hijacking the link. The website's internal, so the likelihood of any sort of attack is pretty slim. Still, I'll keep that in mind. Thanks again!

08-13-2012, 10:23 PM
In the code of my previous post it should be decodeURIComponent, not unencodeURIComponent - I blame this on the code that I originally copied from :thumbsup:

That I'd mention this in case anyone comes across it.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum