Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question targetting iframe from another page - problem with direct linking

    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.ht...s/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

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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>
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Works Great!

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •