Search code examples
javascriptjqueryhtmlcssiframe

Embed a page completely using iframe, no border, no whitespace where the border once was


I have the following code

<html>
<body>
<iframe src="http://anothersite.com" style="width:100%; height:100%;  overflow-y: scroll; overflow-x: hidden;"   marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" seamless="seamless" ></iframe>
</body>
</html>

that has an iframe that I want to display another site in, just like it was a page on the website. However there is some white space that still exists when the border is removed and scrolling bar is still there but it's only still. I want it invisible but still scroll-able, and the border space gone. Please any help would be appreciated. I haven't found a straight forward answer that has worked for me on the browser I am using (Chrome). Thank you.


Solution

  • The page always has a default margin/padding, and that differs between browsers and the mode that the browser uses.

    Add a doctype so that the page isn't rendered in quirks mode (as that makes it less predictable). Add a style sheet that removes the margin and padding from the body element.

    <!DOCTYPE html>
    <html>
    <head>
    <title>Page name</title>
    <style>
    html { height: 100%; }
    body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
    </style>
    </head>
    <body>
    <iframe src="http://anothersite.com" style="width:100%; height:100%;  overflow-y: scroll; overflow-x: hidden;"   marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" seamless="seamless" ></iframe>
    </body>
    </html>