stuff22
stuff22

Reputation: 1672

Open a new browser window in GWT containing a Widget/Panel

I know you can open a new browser window using the Window.open() function directing it to a specific URL. However, is it possible to open a new browser Window containing a GWT Panel? And if it is, can someone show an example of it?

Upvotes: 3

Views: 4224

Answers (1)

Chris Lercher
Chris Lercher

Reputation: 37778

Here's my idea. I implemented it in pure JavaScript, but if it's possible in JS, it should also be possible with GWT!

parent.html:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Parent page</title>
<script type="text/javascript">
    function openChild() {
            window.mychild = window.open("print.html");
            setTimeout('setContent();', 2000);
    }
    function setContent() {
            window.mychild.document.body.innerHTML = 
               '<b>Here is your dynamically generated print content</b>';
               // This could be produced by your main GWT module.
    }
</script>
</head>
<body>
    <a href="#" onclick="javascript:openChild()">Open child window</a>
</body>
</html>

print.html:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Print view</title>
</head>
<body>
    One moment please...
</body>
</html>

Note, that I used a timeout. This isn't ideal, because if the (very small) print.html takes longer to be fetched, then it will overwrite the dynamically set content.

I assume, the solution could be optimized (but make sure that the child window is fetched from the same origin, otherwise you'll run into "Same Origin Policy" problems).

Upvotes: 1

Related Questions