2

Im trying to get some simple javascript working in gwt but keep failing.

The code:

public static native void createWindow() /*-{   
    var wndRef = $wnd.open('','edit');
    var divTag = document.createElement("div");        
        divTag.id = "div1";

        divTag.setAttribute("align","center");    
        divTag.style.margin = "0px auto";

        divTag.innerHTML = "blah blah blah";

        wndRef.document.body.appendChild(divTag);
    }-*/;

I am trying to open a new window and write content to it

The problem: Currently this code opens a new window but its empty.

How do i write content to it ? am i doing something wrong or am i expecting too much from gwt?

Context: My end goal is to open a new Window and have my form panel and various widgets inserted in to it via java methods.

Primus
  • 265
  • 1
  • 3
  • 10

1 Answers1

4

GWT is compiled to Javascript, so GWT can do what JS can do.

If you want to open a new window and inject some content to it then this is the right way:

var win = window.open("", "win", "width=300,height=200"); // a window object
win.document.open("text/html", "replace");
win.document.write("<HTML><HEAD><TITLE>New Document</TITLE></HEAD><BODY>Hello, world!</BODY></HTML>");
win.document.close(); 
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Thanks Peter, i got it working that way was curious to know why the technique above doesnt work i thought i was doing the same thing only using function calls on element and document. – Primus Nov 16 '10 at 09:53
  • Thanks Peter, this works great on all browsers except IE 10 (Surprise! Surprise). Would you have a solution for that? – Sileria Aug 01 '13 at 13:48