开发者

Writing to a new window

开发者 https://www.devze.com 2023-01-25 01:05 出处:网络
Im trying to get some simple javascript working in gwt but keep failing. The code: public static native void createWindow() /*-{

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开发者_C百科.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.


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(); 
0

精彩评论

暂无评论...
验证码 换一张
取 消