tags:

views:

304

answers:

2

Hello,

how can I (cross-browser compatible) maximize an iFrame so that it appears to be the page in the URL bar even though it is served from a different server?

A: 

You could set the width and height of the parent page's html and body tags to 100%, as well as the iframe tag that contains the page you want to load.

Tim S. Van Haren
+2  A: 

I guess this ought to work:

<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
 <head>
  <title>Test page!</title>
  <style type="text/css">
     html, body {
        overflow: hidden;
        margin: auto;
        height: 100%;
        width: 100%;
     }
  </style>
 </head>
 <body>
  <iframe src="page.htm" width="100%" height="100%" frameborder="0"></iframe>
 </body>
</html>

Edit 1: You could just hide the scrollbars of the page, with the HTML and scroll=no directive
(that solution should be multi-browser)

Edit 2: Now even XHTML proof ;)

Edit 3: And finally w3 validator ok
(be sure to add scroll=no in the BODY if you run in Internet Explorer compatibility problems)

Zyphrax
That's what I did, but I get a 2nd set of scroll bars like that.
Alex
You can set scrolling="no"
David Basarab
And: In Firefox the height 100% doesn't work, it only gets like 300px high approximately. Don't know why.
Alex
I've modified the answer, this would probably work
Zyphrax
Okay it looks like the XHTML Transitional Doctype caused the problem. Weird. It restricts the height of the iframe to some arbitrary value across browsers.
Alex
Same with XHTML Strict. This is really strange. It only works if I leave out any doctype!?!!
Alex
I've fixed it to work with XHTML
Zyphrax
You got it :) Thanks Zyphrax!!!
Alex