Solved

Fire exit pop UNLESS a specific button is clicked

Posted on 2011-09-14
3
355 Views
Last Modified: 2012-05-12
I am working on a promotion, where I want to capture someone who is leaving a specific page without adding an item to their cart.

Thus, if they leave that page by clicking the add to cart button, don't fire the exit pop (which offers them a coupon or a discount).

If, however, they exit the page by any other means, I want to have an exit pop that offers them the discount.

I have the exit pop working, but unfortunately, it fires even if they are clicking the add to cart button. So it always offers them the discount.

How do I alter this code so it DOES NOT fire when the visitor clicks on the add to cart button?
 
<script type="text/javascript">
		function PopIt() { 
			$("a#trigger").trigger('click');
			window.onbeforeunload = UnPopIt;
			return "Wait! Don't leave. Click "Say on this page" or "Cancel" and you'll recieve a 50% discount!"; 
		}
		
		function UnPopIt()  { /* nothing to return */ } 

		$(document).ready(function() {
			window.onbeforeunload = PopIt;

			$("a#trigger").fancybox({
				'hideOnContentClick': false,
				'showCloseButton': false
			});

			$("a[id!=trigger]").click(function(){ window.onbeforeunload = UnPopIt; });
		});
	</script>

Open in new window

(FYI... the add to cart button is a form. It uses Authorize.net's simple checkout:

 
<form name="PrePage" method = "post" action = "https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx"> <input type = "hidden" name = "LinkId" value ="767512c3-540d-48e9-8197-xxxxxxxxxxxxxxxx" /> <input type = "image" src ="/images/addtocart-style2.png" /> </form>

Open in new window

0
Comment
Question by:DrDamnit
  • 2
3 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36540162
var displayIt = true;
function PopIt() {
if( displayIt ) {
                  return "Wait! Don't leave. Click "Say on this page" or "Cancel" and you'll recieve a 50% discount!";
}

            }


did not see clearly your onclick event for your addcart button/link but just set inside : displayIt = false;
0
 
LVL 32

Author Comment

by:DrDamnit
ID: 36552799
That's because there is no onclick function. It is just a form with submit as shown in the sample code below the sample code.

Would an onclick event help?
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36552825
not really, add :

<input type = "image" src ="/images/addtocart-style2.png" onclick="displayIt = false;" />
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now