Results 1 to 6 of 6

Thread: Iframe and URL address

  1. #1
    Join Date
    Nov 2007
    Location
    India
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Iframe and URL address

    Hi Experts,

    1.) Question 1

    I've designed a website and used Iframe in it. I've splitted the index page into two, in the left pane there are links and in right pane i've placed iframe. When ever i click on links in left pane it is loading correctly in iframe, i need the link to be displayed in URL of brower.

    Eg.) Consider my domain name is www.mydomain.com and the link page is www.mydomain.com/aboutus.php. When i click on the link the page loads perfectly in iframe and the address "www.mydomain.com/aboutus.php" is not showing in the URL of the browser instead its showing only www.mydomain.com for all the links placed in leftpane

    2.) Question 2

    If I use the link "www.mydomain.com/aboutus.php" directly in the address bar, it is not coming inside the iframe instead the page is loading as individual file and its not coming under my desgin.

    Eg.) When ever a user copys in link in my site and paste in address bar and use it, the webpage should load inside my iframe so that my menus and left pane will be loaded correctly.


    Please help me to sort out the above two queries and i couldnt find any solutions for that. If you have any javascript etc it will really help me.

    Thanks,
    Vidhya Sagar

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    1) The URL in the address bar doesn't change, because the (main) page never changes; only the iframe INSIDE the page changes.

    2) To have the whole page change (together with the iframe), you could put this in each iframe page: <body onload=top.location.replace(location.href>
    (I think that would do it). But that would (perhaps) cause a flicker on page transition.

    3) You could also do this:
    Put this in the body part of each (main) file:
    <iframe name="iframe" src="menu.php" style="width:0px;height:0px" frameborder="0"></iframe>
    <div id="loader" ></div>
    ('menu.php' is a file containing the menu).
    And this in the head section of each (main) file:
    <script ...>
    function callmenu()
    {document.getElementById('loader').innerHTML = frames['iframe'].document.body.innerHTML;}
    window.onload=callmenu
    </script>
    This script will add the contents of menu.php to each (main) file.

    4) But: why don't you simply use an include (no iframe at all)? Php is perfect for that.
    Make a menu.php containing the menu (in plain HTML). Then in the body section of each file:
    <?php include("menu.php"); ?>

    Good luck,
    Arie Molendijk.

  3. #3
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    iframe is like a hidden browser within a page. which is cool, but it is not supposee to show the url of the browser.

    instead of iframes you should make your broswer url like this.
    mydomain.com/index.php?page=index

    here is a simple code..
    Code:
    <?php
    
    $pages = Array(
    
    
    'about_us' => 'pages/about_us.php',
    'contact_us' => 'pages/content.php',
    'forum' => 'forums/content2.php',
    
    
    'error' => '',
    
    );
    
    if (isset($_GET['page']) && array_key_exists($_GET['page'],$pages)) {
       include($pages[$_GET['page']]);
    }
    else {
       include('content.php');
    }
    ?>
    its like an iframe but shows a url, ui use this and i like...
    Hey new design new look, goto xudas for personal webdsign help.. (:

  4. #4
    Join Date
    Nov 2007
    Location
    India
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your replies, I'll try the above solutions and update you.

  5. #5
    Join Date
    Nov 2007
    Location
    India
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi insanemonkey,

    I've tried your code its working perfectly fine, but the page formating gets mismatch. I.e the index page formatting and the frame page formatting both gets mixed up and the format(color, font etc) totally gets collapsed..

    Is there any way to correct this???

    Thanks

  6. #6
    Join Date
    Oct 2006
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Dude, iframes aren't even valid XHTML anymore. Instead, use a page margin, and add absoluted divs containing the navigation and banners at the end. This probably belongs in the HTML forum anyways.

    CSS File
    Code:
    body {
       margin-top: ##px;  // Where ## represents the height of the header bar
       margin-left: ##px;  // Where ## represents the width of the left nav bar
       // margin-right: ##px; See above
       // margin-bottom: ##px; See above
    }
    
    div.header {
       position: absolute;
       left: 0px;
       top: 0px;
       width: ##;  // Whatever you want, for full bar, '100%' is recommended
       height: ##px;  // The value of margin-top, above
      // ... et cetera.
    }
    And besides, you're in the PHP forums. If you wanted, you could put all code for every page into one file, and use a variable, like '$mode' or '$page', or passed through the $_ENV or $_POST superglobals or something, to segregate which parts get loaded.

Bookmarks

Posting Permissions

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