Someone has already asked, How does the DiggBar work? in a previous question.
While someone provided a decent answer it didn’t address one thing:
How does Digg dynamically resize their iframe’s height, based on the content of a site across a different domain?
There are plenty of questions and answers here on SO for dynamically adjusting an iframes height based off content (using javascript) as long as the framed url is on your own domain. However, Digg seems to have solved this problem with websites of any domain.
Do any SO web programmers have any idea how they accomplished that?
Note: The iframe is NOT simply set to 100% height. The iframe tag simply does not work like that. Google ‘100% height iframe’ and you’ll see what I mean.
If you look at their CSS, they use
height: 100%for theiframe:They position the DiggBar above that with a height of
46px, so theiframetakes 100% of the remaining space. They useoverflow: hiddenon thebodyelement to keep theiframeentirely within the vertical height of the page, rather than allowing the page to scroll. This means that the scroll bar will then appear inside theiframe, instead of for the whole page. Note that the the way the DiggBar does it works only in quirks mode in Firefox; see below for how to do it in standards mode.edit: For those who don’t believe me, here is a small example. To get it to fill the entire space, you need to set it to have no border, and you need
<body>to have no margins.edit 2: Ah, sorry, I see what you were talking about. You need the
overflow: hiddenon thebodytag to get the scroll bar to work the way you want.edit 3: It looks like you have to be in quirks mode for this to work in Firefox; if you include a
<!DOCTYPE html>declaration, that puts you into standards mode, and youriframecomes out too small.edit 4: Ah, you can do it in standards mode in Firefox as well. Got the answer here. You need to set the height on your
<html>and<body>elements to100%as well. (Note that the<!DOCTYPE html>is the doctype for HTML 5, which is a work in progress; however, it works on all modern browsers for turning on standards mode).