Results 1 to 2 of 2

Thread: iFrames

  1. #1
    Join Date
    Dec 2002
    Warwickshire, England


    Hi all,

    I am working on a site which has an iFrame to display most of the sites content.

    I have a link on the home page that opens a page that DOES NOT have an iFrame to display the content, but it does have buttons which link back to the home page.


    HOME BUTTON, loads the home page which includes the iFrame, it loads the default content. That work as required.

    PRICE BUTTON, loads the home page as expected with the default iFrame content.

    Is it possible to click the PRICE BUTTON, load the home page and the iFrame containing the price page within the iFrame.

    Any help would be great, many thanks.

    Keep safe and well.


  2. #2
    Join Date
    Jun 2008
    Yes. You can do almost anything you want with iframes...

    To do what you request can be done in two ways...

    If the PRICE button is actually on the home page, just name the iframe and target it.

    If not... then you need to use a bit of javascript.

    Let's suppose you have 2 pages:
    1.) home.html (The parent frame)
    2.) price.htm (The daughter iFrame, or internal frame)

    This little script makes your price.htm page ALWAYS open in the parent window... in this case, home.html:
    HTML Code:
    <SCRIPT LANGUAGE='javascript'>try { if (top == self) {top.location.href='home.html'; } } catch(er) { } </SCRIPT>
    Add the above snippet of script to the head of the page named: price.htm
    Make your hyperlink to price.htm - it will always open inside of home.html

    So... you simply link to the internal page, and make sure that little snippet of JavaScript is in the head. Try it.

    Here is a demo:

    PS- I have developed my own convention for naming files inside and outside of iFrames... I use .htm so I know if a file is an internal frame and always put the above code in it so it cannot open without the parent - otherwise I use the extension .html. Then if I have a lot of files in the same folder, I can tell which are internal iframes and which are not at a simple glance.
    Last edited by donatello; 11-28-2009 at 08:54 PM. Reason: clarification of example...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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