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 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    67
    Thanks
    14
    Thanked 6 Times in 6 Posts

    Linking 2 sites with seperate IFRAMES

    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?

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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.

    Code:
    pageA.htm:
    <a href="pageb.htm?iframepage1.html">Iframe page 1</a><br> 
    <a href="pageb.htm?iframepage2.html">Iframe page 2</a><br> 
    
    PageB.htm:
    <!DOCTYPE html>
    <html> 
    <head> 
    <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";
        }
    } 
    window.onload=loadIframe;  
    </script>
    
    </head>
    
    <body> 
        <iframe name="myiframe" id="myiframe" src=""></iframe> 
    </body> 
    </html>
    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.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    superwookie (08-09-2012)

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    67
    Thanks
    14
    Thanked 6 Times in 6 Posts
    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!

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    In the code of my previous post it should be decodeURIComponent, not unencodeURIComponent - I blame this on the code that I originally copied from

    That I'd mention this in case anyone comes across it.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

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