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