Log in

View Full Version : Iframe and URL address



kvs1983
11-05-2007, 06:00 AM
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

molendijk
11-05-2007, 06:22 PM
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.

insanemonkey
11-06-2007, 05:35 PM
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..

<?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...

kvs1983
11-07-2007, 11:03 AM
Thanks for your replies, I'll try the above solutions and update you.

kvs1983
11-11-2007, 03:59 AM
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

Shotgun Ninja
11-21-2007, 04:27 PM
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


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.