2014-01-07 96 views
0

在我的網站的購物車頁面上,我必須攔截用戶離開頁面並詢問他們是否想通過電子郵件保存購物車。在離開頁面之前保存用戶電子郵件

我想我必須使用事件「beforeunload」攔截用戶離開該頁面,但我有兩個問題:

  • 如何從「beforeunload」排除觸發的點擊鏈接繼續付款?

  • 如何提示一個小型表單,我可以要求他的電子郵件(稍後以某種方式使用),然後繼續卸載頁面?

+0

您的代碼到目前爲止? – Goikiu

+0

我剛開始考慮這個,所以我現在沒有提交有趣的代碼 – marcosh

+0

你看看其他人(magento,oxid,shopware)是如何做到這一點的嗎? –

回答

0

ü可以做的是使出現一個默認瀏覽器消息框的唯一的事情...

window.onbeforeunload = foo; 

function foo(e) { 
     if (!e) e = window.event; 
     //e.cancelBubble is supported by IE - this will kill the bubbling process. 
     e.cancelBubble = true; 
     e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog 

     //e.stopPropagation works in Firefox. 
     if (e.stopPropagation) { 
      e.stopPropagation(); 
      e.preventDefault(); 
     } 
} 
1

爲了排除鏈路上與支付繼續進行,你可以這樣做: -

window.onbeforeunload = function() { 
    return "You're leaving the site."; 
}; 
$(document).ready(function() { 
    $('a[rel!=ext]').click(function() { window.onbeforeunload = null; }); 
    $('form').submit(function() { window.onbeforeunload = null; }); 
}); 
相關問題