...

View Full Version : targetting iframe from another page - problem with direct linking



gjuddy
12-07-2004, 03:11 PM
I'm having a problem with a javascript that I found online...it works great and does exactly what I need it to do except for 1 issue.

If you go here:

http://www.walnutinfo.com/index.html

and click on recipes in the left hand menu, you'll be directed to the recipe page with this link:

http://www.walnutinfo.com/recipes.html?recipes/feature.html

The reason for the "?recipes/feature.html" at the end of the link is that I've got an iframe on the recipes page and I want to be able to target that iframe from other pages. ok, works perfectly except...you can't link directly to the recipes page (http://www.walnutinfo.com/recipes.html) or the iframe gets totally screwed up.

My question is...is there a way to modify this script so that you can designate a default iframe source if someone tries to go directly to the page?

The script on the recipe page consists of this in the head tag:

var newURL = unescape(location.search.substring(1));

and this in the body tag:

onLoad="parent.content.location.href=newURL; (with "content" being the name of the iframe)

I then leave the src tag of the iframe blank...which is why it screws up if it doesn't receive the proper info from the sending page.

Any help would be greatly appreciated.

Thanks

Mr J
12-07-2004, 05:53 PM
You need something like the following,

In the parent page.

<script language="JavaScript">
<!--
loc="page1.htm" // default page to load into Iframe
var str = location.search;
if(str != ""){
loc=str.substring(1, str.length)
}

function load_frame(){
document.getElementById('iframe_id').src=loc // change iframe_id to the ID of your Iframe
}

// add onload="load_frame()" to the opening BODY tag

// -->
</SCRIPT>


In the page loading into the iframe

<script language="JavaScript">
<!--
if (self == top){
var url = self.location;
self.location = "parent_page.htm?" + url; // name of parent page
}
// -->
</SCRIPT>

gjuddy
12-09-2004, 08:27 PM
Thanks alot for your help Mr. J! I couldn't get it to work at first but eventually I combined what you gave me with what I already had and got it to work perfectly.

so I ended up with this in the head tag of the parent doc:

loc="recipes/feature.html"
var str = location.search;
if(str != ""){
loc=str.substring(1, str.length)

and this in the body tag:

onLoad="parent.content.location.href=loc;

Thanks again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum