javascript - Pop-up when leaving website -


i've been asked have pop-up when visitors leave site asking them if want leave. pop-up show if shopping cart has items in it.

i can limit pop-up when cart has items, issue i'm having clicking internal link loads pop-up - how can have comes when leaving site.

<script language="javascript">   window.onbeforeunload = confirmexit;   function confirmexit()   {     return "some message leaving";   } </script> 

if link clicked, tell in e.target.activeelement. can check if it's link there:

window.onbeforeunload = confirmexit; function confirmexit(e) {     var $element = $(e.target.activeelement);     if ($element.prop("tagname") !== "a") {         return "some message leaving";     } } 

note: can add additional conditions checking $element.attr("href") make sure displays message links aren't site.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -