PDA

View Full Version : PHP instead of Iframe



Rohan72
08-16-2008, 01:31 AM
I'm working on a site with a css layout, but it still has an Iframe in it.
I would like to get rid of that Iframe.

I was thinking of changing it to a <DIV> and load the pages thru PHP.

Is that possible? if yes, how would i do that?

rangana
08-16-2008, 01:41 AM
iframe is an HTML tag. It's not PHP.

You might mean to use include() (http://us3.php.net/include/) instead (which is php).

Hope that helps.

Rohan72
08-16-2008, 02:07 AM
I'm just a beginner with php, but know my way around html and css.
now I would like to get rid of the last frames (iframes) on any site I am making.
Here is an example of what i am talking about.



<a href="site2.html" target="site">to site2</a>

<iframe src="site.html" name="site" width="585px" id="site" scrolling="no" frameborder="0" allowtransparency="true"></iframe>


I would like to throw out the Iframe and just use a Div instead, so its easier to maintain the layout of the page.
The way I'm thinking is that the Iframe is replaced with a Div and that the content of that Div (in this case site.html) is called upon by PHP.
Also the link (site2.html) would be be inserted into the Div by PHPand replace the first content.

Can anyone provide me with an example (based on my example) ?

TheJoshMan
08-16-2008, 02:11 AM
You could use AJAX to do just that...

http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

surfandsnow
01-10-2010, 12:58 AM
You could use AJAX to do just that...

http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm


The problem I found with this Ajax script was that after calling my forum index script

/phpbb/index.php

it would would consider all phpbb's links as starting from the root folder, instead of the phpbb folder. Basically, all the links to directories would read..

./images/forumlogos/filename.jpg

instead of

./phpbb/images/forumlogos/filename.jpg


...Hope that makes sense.

Is there any way to correct this?

Thanks

djr33
01-10-2010, 02:07 AM
1. include() tags the contents of one page and puts it in another.
<div><?php include('something.htm'); ?></div>
Is roughly equivalent to <iframe src="something.htm"></iframe>

2. An iframe is not "part" of the page-- instead it is displaying two pages at once. Everything between the two is separate, including the base paths for links. Any method you use aside from iframes (ajax, php includes, etc) will not work with relative links-- they will be adjusted as they are now PART of the main page (not just embedded as a separate page (iframe) in it).


If you want to include full pages as they are into other pages, then the best way to do this really is to use an iframe or perhaps full frames (using a frameset page-- slightly more compatible, but also a little harder to code and less control over the size of the frames-- they can't just be a small part of the page, but instead fill up an entire portion of the page-- either top-bottom or left-right).


Using PHP includes is a great way to include content (specially stored content so that it works smoothly with the rest of your code), but they will be very messy if you are including full pages within full pages. This means that you are doing, effectively:
<html>.......<html>....</html>...</html>
And that is completely invalid, not to mention just messy and hard to work with.

For this reason, full pages should actually be included with frames because that way the head and body sections can both be included normally, so that scripts, css, etc. work in the "included" page.

If you do use PHP includes or another similar method, then the only part you can effectively include is a portion of the body. Trying to add elements from the head (formatting, scripts, etc), OR trying to change a property (like the base path for links) is nearly impossible, at least without doing a lot more work in the overall conception of the site (and still you would need to specially design the included pages).


Iframes have their problems, but they are much easier to deal with for this sort of thing than the alternatives, because they are able to keep the content separate from the rest of the page.

surfandsnow
01-10-2010, 03:42 AM
DJR33,

thanks for the response. That is what I've figured it while browsing the web after I posted my concern.

The site I'm working on uses the iframe for the phpbb forum only, so I will probably end up sticking to this method until I find an alternative method.

djr33
01-10-2010, 05:09 AM
The only real alternative method is to modify the forum in a major way so that:
1. All links (and other paths, like for images and scripts) are absolute, that is that they are in the format "http://....yoursite.../file", OR '/directory/file', as both will act independently of the location from which they are called.
2. There is an alternate template for the forum in which ONLY body elements exist (that is-- the <html> tags and <head> section are entirely removed, as well as the <body> tag itself).

If both of those work, then in theory, it will be possible to put it in a div.

However, that requires a lot of work and might still be messy for a few reasons. So I'd say just use the iframe if you want this, or find another way (overall) to design the whole site-- there won't be an easy way to get rid of the iframes otherwise.