2012-02-16 16 views
0

在我的GWT應用程序中,我通過Recurly接收付款,並在IFrame中使用Recurly的頁面。當Recurly成功處理付款時,他們的頁面會重定向到我提供的成功URL,它會以POST命中我的servlet。收到POST後,我想關閉IFrame並對我的小部件執行操作。我關閉使用JavaScript的IFrame的響應:在GWT應用程序中,如何使用doPost的響應來關閉IFrame

@Override 
protected void doPost(HttpServletRequest request, HttpServletResponse response) 
    throws ServletException, IOException { 
    /* other code */ 
    StringBuilder buf = new StringBuilder(); 
    buf.append("<script language=\"javascript\" type=\"text/javascript\">"); 
    buf.append("var n = window.parent.document.getElementById(\"recurly-popup\");"); 
    buf.append("n.parentNode.removeChild(n);"); 
    buf.append("</script>"); 
    response.getOutputStream().print(buf.toString()); 
} 

不過,我似乎無法找到任何方式在iframe是關閉了客戶端上檢測到。我如何使用GWT或GWTQuery檢測它?

回答

0

您可以嘗試添加一個Javascript偵聽器(通過GWT的JSNI)。 FF和IE瀏覽器需要的聽衆記錄在這裏:http://bytes.com/topic/javascript/answers/627389-having-trouble-event-listener-detect-iframe-close-event-fromparent

另一個可能的選擇是在您移除iframe之前,可能正在對父級執行JavaScript函數(例如發送事件)。類似於:

buf.append("<script language=\"javascript\" type=\"text/javascript\">"); 
buf.append("window.parent.document.myGWTJSNIFunction('recurly_processed_event');"); 
buf.append("var n = window.parent.document.getElementById(\"recurly-popup\");"); 
buf.append("n.parentNode.removeChild(n);"); 
buf.append("</script>"); 

道歉,如果Javascript不正確,它尚未經過測試。有關GWT JSNI的更多詳細信息,請訪問:http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html

相關問題