Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

gwt

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?

like image 934
stuff22 Avatar asked Dec 01 '25 04:12

stuff22


1 Answers

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).

like image 70
Chris Lercher Avatar answered Dec 02 '25 16:12

Chris Lercher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!