2014-02-28 24 views
0

我正在使用我的django網站中的Paypal付款高級嵌入/託管結帳頁面。我爲貝寶付款頁面顯示一個iframe,我提交請求,並將其發回到我的網站。如何重定向整個頁面時Django iframe的遠程職位

處理該貝寶響應視圖使用

response = redirect("shop_complete") 
return response 

但是這使得我的整個響應頁面彈出的iframe中。我可以使用一個在該位置看起來完全正確的模板,但我想同時更新購物車和付款步驟。無論如何,要讓響應重定向整個瀏覽器而不是框架?

+0

所以,如果你是重定向整個頁面這個腳本,會在iframe重定向什麼以後? – Drewness

+0

基本上,您需要在返回iframe的頁面中使用javascript,才能在頂級瀏覽器窗口中加載新url(也可以使用元標記完成) – Anentropic

+0

訂單完成頁面上不會有iframe。 –

回答

0

因此,我的解決方案最終添加了一個完全由腳本組成的中間頁面,以重定向瀏覽器的頂層。我從

JavaScript post request like a form submit

<body> 

<script type="text/javascript"> 
function post_to_url(path, params, method) { 
    method = method || "post"; // Set method to post by default if not specified. 

    // The rest of this code assumes you are not using a library. 
    // It can be made less wordy if you use one. 
    var form = document.createElement("form"); 
    form.setAttribute("method", method); 
    form.setAttribute("action", path); 
    form.setAttribute("target", "_top") 

    for(var key in params) { 
     if(params.hasOwnProperty(key)) { 
      var hiddenField = document.createElement("input"); 
      hiddenField.setAttribute("type", "hidden"); 
      hiddenField.setAttribute("name", key); 
      hiddenField.setAttribute("value", params[key]); 

      form.appendChild(hiddenField); 
     } 
    } 

    document.body.appendChild(form); 
    form.submit(); 
}; 
window.onload = post_to_url('{% url "shop_paypal_redirect" %}', 
     {csrfmiddlewaretoken: '{{ csrf_token }}', 
      result: '{{ result }}'}); 
</script> 
</body> 
相關問題