Access newly Opened window in gwt

64 views
Skip to first unread message

Sarjith Pullithodi

unread,
Nov 8, 2012, 5:46:09 AM11/8/12
to google-we...@googlegroups.com

I am trying to achieve something like below through GWT (below code is javascript).



function openWin() {
   var myWindow=window.open('','','width='+screen.width+',height='+screen.height+',left='+screen.width);
   myWindow.document.write("<p>This is 'myWindow'</p>");
   myWindow.document.write("<span id='span'></span>");
   myWindow.document.close();

   myWindow.document.getElementById('span').innerText = 'something';
}


How can I achieve this in gwt, when i try this javascript code itself, inside my gwt project, left='+screen.widthis not seems to be working in FF and myWindow.document.getElementById('span').innerText = 'something'; is not seems to be working in chrome. correcting them in javascript is also fine for me, as long as it works perfect for both FF and chrome.

Regarding using the PopupPanel of gwt, that also wouldnt help me. As far as I know, PopupPanel can't be poped out of the page. In my scenario, the new window should be opened in my secondory display (which can be achieved with current js code. using code'width='+screen.width+',height='+screen.height+',left='+screen.width. (If I am wrong please guide me to know about such property of PopupPanel.


--
Sarjith
          

Thomas Broyer

unread,
Nov 8, 2012, 9:49:44 AM11/8/12
to google-we...@googlegroups.com
The 'screen', 'window.open()', 'myWindow.document' and 'document.write()' will have to be done in JSNI. For the screen, maybe you need $wnd.screen (seems unlikely though). Easiest would be to do them all in one method:

public native Document openWin() /*-{
   var myWindow=window.open('','','width='+screen.width+',height='+screen.height+',left='+screen.width);
   myWindow.document.write("<p>This is 'myWindow'</p>");
   myWindow.document.write("<span id='span'></span>");
   myWindow.document.close();

   return myWindow.document;
}-*/;

And then:

   Document doc = openWin();
   doc.getElementById("span").setInnerText("something");

I believe your issue with left=screen.width is due to Firefox; does it work in pure JS?

Also, keep in mind that you won't be able to use widgets in that other window (it might work, but it has good chances to fail at some point)
Reply all
Reply to author
Forward
0 new messages