Search code examples
gwt

How can I add <!DOCTYPE html> inside an iframe in GWT?


I've created an IFrame with no src in my GWT project but as I don't have <!DOCTYPE html> inside it some css properties are being overriden by the user agent stylesheet. Is there any way I can add <!DOCTYPE html> inside the IFrame element?


Solution

  • I guess that you want to have an empty iframe to manipulate programmatically.

    The easiest way is to create minimal html file with <!DOCTYPE html> and set src attribute to that file.

    <!DOCTYPE html>
    <html>
        <head>
            <title>Title</title>
        </head>
        <body>
        </body>
    </html>
    

    Save this file is the war folder as empty.html for example. Then use:

    IFrameElement iframe = Document.get().createIFrameElement();
    iframe.setSrc("empty.html");
    

    to get Element. If you want to have a Widget add:

    new HTML(iframe.toString());