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?
+1
A:
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).
Chris Lercher
2010-06-10 18:06:52
That's actually a great idea, Chris :) It should do the job nicely as long as you expect to put only static content/HTML into that window - any event handlers, etc. won't get transferred (obviously). And I just wanted to add, that one can access the innerHTML value for any Widget via `getElement().getInnerHTML()`. So to get the whole body tag, one would use `RootPanel.get().getElement().getInnerHTML()`.
Igor Klimer
2010-06-10 19:39:39