2012-02-24 3 views
3

다른 웹 URL을 가리키는 프레임이있는 GWT 애플리케이션이 있습니다. frame.setUrl (other web url);GWT를 사용하여 액세스 프레임의 문서

가끔씩 다른 웹 URL에서 오류가 발생할 수 있습니다. 예를 들어 네트워크 오류 또는 페이지를 사용할 수없는 경우 해당 오류를 구문 분석하고 내 GWT 응용 프로그램에 사용자에게 친숙한 오류 메시지를 표시해야하지만 방법을 알 수 없습니다. 액자와 함께 해보니, 내가 시도 :

frame.addDomHandler(new LoadHandler() { 

      @Override 
      public void onLoad(LoadEvent event) { 
       Window.alert("loaded!"); 

       IFrameElement iframe = IFrameElement.as(frame.getElement()); 
       Document frameDocument = getIFrameDocument(iframe); 
       if (frameDocument != null) { 
        Window.alert(frameDocument.getDomain()); 
       } 
       else { 
        Window.alert("the document is empty, nothing to display!"); 
       } 

      } 
     }, LoadEvent.getType()); 
    } 

    private native Document getIFrameDocument(IFrameElement iframe) /*-{ 
     return iframe.contentDocument; 
    }-*/; 

항상 null로 문서를 반환합니다, 나는 그게 - orign 정책 때문인 것 같아요. GWT에서 프레임 문서에 어떻게 액세스 할 수 있습니까? 감사합니다

답변

1

getIFrameDocument() JSNI 방법을 사용하는 대신 GWT에서 제공 한 IFrameElementiframe.getContentDocument()을 호출 해보십시오. 여기에 the javadoc for that method입니다.

관련 문제