Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
访问框';使用GWT的s文档_Gwt - Fatal编程技术网

访问框';使用GWT的s文档

访问框';使用GWT的s文档,gwt,Gwt,我有一个GWT应用程序,它有一个指向其他web url的框架,如:frame.setUrl(其他web url) 但有时可能会有来自其他web url的错误,例如网络错误或页面不可用,我需要解析这些错误,并在GWT应用程序中显示一条用户友好的错误消息,但无法找出如何使用框架执行此操作,我尝试了: frame.addDomHandler(new LoadHandler() { @Override public void onLoad(LoadEve

我有一个GWT应用程序,它有一个指向其他web url的框架,如:frame.setUrl(其他web url)

但有时可能会有来自其他web 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中的框架文档呢?感谢您不要使用您的原生
getIFrameDocument()
JSNI方法,请尝试在GWT提供的
iframe元素上调用
iframe.getContentDocument()
。给你