简体   繁体   English

在包含Widget / Panel的GWT中打开一个新的浏览器窗口

[英]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. 我知道您可以使用Window.open()函数打开一个新的浏览器窗口,将其指向特定的URL。 However, is it possible to open a new browser Window containing a GWT Panel? 但是,是否可以打开包含GWT面板的新浏览器窗口? And if it is, can someone show an example of it? 如果是的话,有人可以展示它的一个例子吗?

Here's my idea. 这是我的想法。 I implemented it in pure JavaScript, but if it's possible in JS, it should also be possible with GWT! 我在纯JavaScript中实现它,但如果它在JS中可行,那么它也应该可以用GWT实现!

parent.html: 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: 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. 这并不理想,因为如果(非常小的)print.html需要更长的时间来获取,那么它将覆盖动态设置的内容。

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). 我假设,解决方案可以优化(但要确保从同一个源获取子窗口,否则您将遇到“同源策略”问题)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM