Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed section of HTML from another site?

Tags:

html

embed

Is there a way to embed only a section of a website in another HTML page?

Example: I see an answer I want to blog about, so I grab the HTML content, and splat it in somewhere, and show only that, styled like it is on stackoverflow. Basically, I want to blockquote the section of the page with original styling, if that makes sense. Is that something the site itself has to provide, or can I use an iframe and tell it to show only a certain element or something crazy? Open to all options, but I want it to show up as HTML, not as an image (that's really a last resort).

If this is even possible, are there security concerns I need to aware of?

like image 684
Daniel Huckstep Avatar asked Dec 23 '22 10:12

Daniel Huckstep


2 Answers

Don't think image should really be last resort. You have no control over the HTML/CSS of the source page, so even if you craft a solution (probably by using JavaScript to parse out the desired snippet) there is no guarantee that tomorrow the site doesn't decide to change its layout.

Even Jeff, who has control over the layout of stackoverflow.com, still prefers to screen-capture the site, rather than pull in the contents live.

Now if your goal was to have the contents auto-update, that would be a different story. But still, unless you use some agreed-upon method of sharing content, such as RSS, your solution would be very fragile.

like image 79
Eugene Katz Avatar answered Jan 12 '23 08:01

Eugene Katz


The concept you are describing is roughly what is called a "purple include" or "transclusions". There is a library out there for it, but its not exactly actively developed. Here's a couple ajaxian articles on it.

like image 29
Russell Leggett Avatar answered Jan 12 '23 10:01

Russell Leggett