How do I prevent a webpage that I normal load in a IFrame from being loading on its own.

Posted on 2006-05-17
Last Modified: 2008-03-10
I have a main page with my navigation on it.  There is a IFrame on this page that I use for loading other pages keeping my navigation and my title always in place.  I have seen example for how to do this with frames but I am not having luck getting the same code to work for an IFrame.
Question by:TBWDEVELOP
    LVL 20

    Expert Comment

    assign name to your iframe and use javascript . as u can do in frame
    LVL 6

    Expert Comment

    I would not use IFRAME at all, as some browsers can have it's support totally disabled due to security settings while others don't support IFRAMEs at all.
    Frameset is, however, supported even by older browsers - I would go this way, if you need frames on your page.
    Of course you can ignore this comment, resulting in (possibly very few) people being unable to navigate throughout your page.

    ... and that frameset code you came across - will work for you, too :-)

    Author Comment

    Okay if I roll back the use to a 3 frame page.  Top, Left, Main the normal stuff.  The problem I then run into is how to get my popup menu control that is in the Left frame to break out of that frame and display across the Main frame.  And I can't not inbed code on a couple of the pages that I would load into the Main Frame to support the pop up menu.
    LVL 6

    Accepted Solution

    Okay, seems you would have some design problems with those famesets.
    I just don't quite understand the part about your popup menu. What sort of popup menu it is? Is it one that expands over whole page width?

    Regarding that restriction, you might be able to use "parent.document.location" to check whether parent page is your main website.
    As an example, "parent.document.location" will say "" if content is loaded into IFRAME or "" if your page is loaded on its own outside that IFRAME.

    Hope this helps.

    Also, try to think about design without IFRAMES or FRAMES when possible, as this is not very recommended these days.
    I know that it's much easier to use frames when you create a static page and I would use frames myself in such a situation. Gladly, I do PHP websites :-)
    LVL 1

    Assisted Solution

    Add this to the page that loads in the iframe...

    <script type="text/javascript">
    if(self.location.href == top.location.href){
    location.href = "index.htm"; // or whatever page you would rather load that contains your iframe

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Hire Freelancers to Complete JavaScript Projects

    Source the talented Expert Exchange community
    for top quality work on your JavaScript projects.

    Hire the best. Collaborate easily. Get quality work.

    Both jQuery and Mootools offer some nice, easy to use scripts. Mootools is best known for their interactive slideshows and jQuery for their menus, but both have many other uses as well.   jQuery is basically a toolkit with many DOM (http://en.wik…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now