【发布时间】:2016-07-14 16:07:46
【问题描述】:
我正在创建一个包含 Frame 小部件的 DialogBox。我尝试使用 addLoadHander 和 addAttachHandler 钩子来尝试捕获对框架的更改,但没有成功。只有初始页面加载会触发任一事件,经过一些研究后,似乎两者都在 Widget 附加到 DOM 时实际发生,而不是在加载框架内容时发生。
DialogBox paymentProcessingDialog = new DialogBox(false);
private void submitPayment(String actionURL, String qryString){
Frame processCCWindow = new Frame(actionURL + "?" + qryString);
processCCWindow.addLoadHandler(new LoadHandler() {
@Override
public void onLoad(LoadEvent event) {
//This is called when the frame is attached to the dom
//and not when the document is actually ready so it's
//kinda worthless for my scenario
//Note: the addAttachHandler has the same issue
//***call to JSNI idea (see below)
checkURLChange();
}
});
//...irrelevant code to style the DialogBox
VerticalPanel panel = new VerticalPanel();
panel.add(processCCWindow);
paymentProcessingDialog.setWidget(panel);
paymentProcessingDialog.center();
paymentProcessingDialog.show();
}
加载到框架中的 URL 包含来自外部服务器(Paypal - 透明重定向)的 HTML 响应,该响应会立即通过表单将自身重新提交回我的服务器。一旦提交回我的服务器完成并且框架中的文档已加载,我正在尝试捕获框架的主体。
我还尝试使用使用 MutationObserver (got the code from this solution) 的 JSNI 方法来尝试观察框架,但我相信 JSNI 实际上是在父级内部运行而不是在框架内部运行(?)所以没有任何反应.
我也尝试使用 setTimeout 在演示者类中触发另一个方法,但我认为这与 MutationObserver 想法遇到了相同的问题,因为控制台语句永远不会触发。
private static native void checkURLChange()/*-{
new MutationObserver(function(mutations) {
mutations.some(function(mutation) {
if (mutation.type === 'attributes' && mutation.attributeName === 'src') {
console.log(mutation);
console.log('Old src: ', mutation.oldValue);
console.log('New src: ', mutation.target.src);
return true;
}
return false;
});
}).observe(location.href, {
attributes: true,
attributeFilter: ['src'],
attributeOldValue: true,
characterData: false,
characterDataOldValue: false,
childList: false,
subtree: true
});
window.location = "foo";
setTimeout(function() {
@com.myPackage.MyoutPresenter::paymentProcessComplete(Ljava/lang/String;)(document.getElementsByTagName("body")[0].innerText);
console.log("test" + document.getElementsByTagName("body")[0].innerText);
}, 3000);
}-*/;
有人对我如何实现这一点有任何想法吗?
【问题讨论】:
-
即使观察有效,由于浏览器限制,我认为您无法获取框架的内容,因为它是来自另一个域的页面。
标签: gwt frame onload-event