2013-03-31 95 views
3

我有一個父頁面,它有PayPal按鈕。按下按鈕將觸發一個迷你瀏覽器,用戶可以登錄並付款。PayPal Express Checkout後重定向父頁面

以下代碼在用戶付款成功後關閉PayPal mini瀏覽器。

// Add javascript to close Digital Goods frame. You may want to 
       // add more javascript code to 
       // display some info message indicating status of purchase in 
       // the parent window 
       response.setContentType("text/html"); 
       response.getWriter() 
         .println(
           "<script>\n alert(\"Payment Successful\");\n// add relevant message above or remove the line if not required \n window.onload = function(){\nif(window.opener){\nwindow.close();\n}\nelse{\nif(top.dg.isOpen() == true){\ntop.dg.closeFlow();\nreturn true;\n}\n}\n};\n</script>"); 

迷你瀏覽器已成功關閉,但我的應用程序上的父頁面保持不變。如何使用付款狀態更新父頁面?

回答

5

我通過在window.close();之前添加以下JS代碼來解決此問題,以便在父頁面訪問表單。獲得表格後,我可以提交頁面或顯示關於狀態的對話框通知。

window.onload = function() { 
    if (window.opener) { 
     window.opener.document.forms[0].submit(); // submit form 
     window.close(); 
    } else { 
     if (top.dg.isOpen() == true) { 
      top.document.forms[0].submit(); // submit form 
      top.dg.closeFlow(); 
      return true; 
     } 
    } 
};