2012-11-23 4 views
0

URL이있는 윈도우를 여는 gwt java 코드 프로그램이 있습니다.창이 열리기 전에 창이 열려 있는지 확인하십시오.

Map<String, Object> ids = new HashMap<String, Object>(); 
        ids.put("employeeId", UserToken.getCurrentUserToken().getEmployeeId()); 
        createCaseUrl = ICMIntakeConstants.buildGrailsUrl(ICMIntakeConstants.CLIENT_APPLICATION_CONTROLLER, "", ids); 
        ICMWindow.open(createCaseUrl, "intake", "height=600,width=800,scrollbars=yes,resizable=yes,toolbar=no,directories=no,status=no,menubar=no", true); 

이 (그러나 IE와 크롬이 파이어 폭스를 처리하지만) 어떤 이유로 두 번 호출되는 코드의 문제점은, 그 창은 Firefox.I에 두 번 팝업 왜 방법을 알 필요가있다 이것을 막으십시오. 윈도우의 JSNI 코드를 수정하려고했지만 배경이 0이고 연구를 수행했을 때 간단한 경고가 나타나지 않아서 실제로 디버깅을 수행 할 수 없었습니다.

/** 
* Defines all variable in JavaScript accessible by Java code and opens a new browser window 
* with the specified url, name and features. 
*/ 
public static native void open(String url, String name, String features, boolean force) 
/*-{ 
    $wnd.alert("test2"); 
    var winRef; 
    try { 

     if (force) 
     { 


       winRef = $wnd.open(url,name, features); 

        $wnd.alert("test1 force"); 
        Alert.alert("clicked!"); 

     } 
     else 
     { 
      $wnd.alert("test2"); 
      winRef = $wnd.open("",name, features); 
      if(winRef.location == 'about:blank') 
      { 
        winRef.location=url 
      } 
      else 
      { 
        if(!/Chrome[\/\s]/.test(navigator.userAgent)) 
        { 
         winRef.alert("Please click Ok To Continue...."); 
        } 
      } 
     } 

     // Set focus to the opened window 
     winRef.focus(); 

    } catch (err) { 
    }   
}-*/; 

나는 ... JUnit 테스트하지만 아무것도를 통해 open() 메서드를 호출하려고

나는 경우도 작동하지 않습니다 위의 코드 사촌 경고 팝업을 만들 수있는 방법 아무도 말해 줄 수 전체 코드를 지우고 방금 $ wnd.alert ("test2");를 남겼습니다. 그리고 JSNI에 winref가 있는지 확인한 다음 어떻게하면 창을 열지 않을 수 있습니까? Pls 도움.

또는 내가 열리는 창에 자바 스크립트 코드를 삽입 할 수있는 방법이 있습니까? 이 문제를 해결하는 가장 좋은 방법은 무엇입니까? 감사합니다.

답변

0

닫힌 지 여부를 묻는 메시지가 표시되도록 열린 창에 대한 참조를 유지해야합니다. 여기에 실례가 있습니다.

private native Element open(String url, String name, String features) /*-{ 
    return $wnd.open(url, name, features); 
    }-*/; 

    private native boolean isOpen(Element win) /*-{ 
    return !! (win && !win.closed); 
    }-*/; 

    private native void close(Element win) /*-{ 
    if (win) win.close(); 
    }-*/; 

    private native void focus(Element win) /*-{ 
    if (win) win.focus(); 
    }-*/; 

    private Element win = null; 

    public void onModuleLoad() { 

    Button open = new Button("Open Win"); 
    Button close = new Button("Close Win"); 
    RootPanel.get().add(open); 
    RootPanel.get().add(close); 


    open.addClickHandler(new ClickHandler() { 
     public void onClick(ClickEvent event) { 
     if (!isOpen(win)) { 
      win = open("http://www.google.com", "myWin", "height=600,width=800,scrollbars=yes,resizable=yes,toolbar=no,directories=no,status=no,menubar=no"); 
     } 
     focus(win); 
     } 
    }); 

    close.addClickHandler(new ClickHandler() { 
     public void onClick(ClickEvent event) { 
     close(win); 
     } 
    }); 

    } 
관련 문제