views:

469

answers:

4

Hi,
i'm looking for a way to display a web page inside a div of other web page.
i can fetch the the webpage with CURL, but since it has an external stylesheet when i try to display it, it appears without all his style properties.
i remember facebook used this technique with shared links (you used to see the page that was linked with a facebook header) did some unsuccessful jquery tests but I'm pretty much clueless about how to continue..
i know this can be done with frames but i always here that it's good practice to avoid frames so i'm a bit confused
any ideas how to work this out?

+2  A: 

If you want to display the other website's contents exactly as they are rendered in that site then frames are, in this case, the best (easiest) way to go.

Facebook and Google both use this technique to display pages while maintaining their branding / navigation bar above the other site.

Sean Vieira
Thanks for that, will go with the frame solution. do you know by chance is it possible to enable closing of the 'header' frame thus let the user remain with the original page?
Yaniv
@Yaniv Do you mean is it possible to visually wrap your page about the other page rather than just doing a header banner? If so, then yes. I would recommend looking up iframe and its many implementations.
Sean Vieira
well, after investigating for a while looks like this is very uncommon to do since iframe won't adjust it's height according to the content in it.. there are some workarounds but most of them won't work if the iframe content is from other domain (which it is in my case)..bummer.. will have to think it over again
Yaniv
+1  A: 

I am going to guess that Facebook still used an iFrame, just with no borders and a well placed header outside of it. The reason I am guessing that is because if the outside page has its own style sheet, there is a high probability that your styles and their styles will clash and not show things properly.

In order for the styles not to clash everything on both ends would have to be extremely detailed, not just generic styles applied to all paragraphs etc...

Jimmy
+1  A: 

i agree that using frames would probably be the best solution for you problem. but if you still want to avoid frames and put the contents into a div with the id externalConent, you could request the stylesheets the same way you get the other contents and prefix every rule in them with "#externalContent ". save these stylesheets to your server and include them in your page. with a few more customizations, that should work. i have to admit this solution does sound quite strange... well, it is. but it's the only way i see to do what you're asking for.

Timo
You would also then have to change all of the HTML class references.. This seems a bit overkill just to display an external webpage. (Ever wrote an HTML parser and CSS Parser?)
Earlz
yeah that sound like a big headache :) iframe it will be.. :)thanks
Yaniv
A: 

If you are unable to use a frame or iframe, try:

  • extract the HTML inside the BODY and inserting it into the destination DIV
  • extract the and sections at the header

Is not very clean though, but it will definitely work, you can insert a phpBB forum into another dynamic way using this technique, take a look at http://www.clearerimages.com/forum/ for an example.

Ast Derek