Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
96
rated 0 times [  102] [ 6]  / answers: 1 / hits: 24941  / 12 Years ago, sun, june 17, 2012, 12:00:00

I'm looking to implement a warning if the user attempts to leave the order process before it's completed in any fashion other then of course following the payment button.



Something like this:



<script type=text/javascript>
window.onbeforeunload = function(){
return 'You must click Buy Now to make payment and finish your order. If you leave now your order will be canceled.';
};
if document.getElementsByClassName('eStore_buy_now_button').onclick = function(){
};
</script>


I'm sure that's detrimentally wrong in a few ways, but it's the best way I can illustrate what I'm trying. And I understand some browsers will display default text instead of the actual warning I've written, that's fine.



A few notes, I'd rather use plain old JS instead of loading up jQuery for just this one simple task. There are no settings on the page so it's a simple leave page or click Buy Now operation.



UPDATE:



I assure you it's not for my sake, it's for the user's sake. Although it's explicitly explained (what to do), I think user's are jumping the gun and leaving before the process is truly finished out of an instant gratification, ignore the messages kind of mentality. It's a simple 2-step process, they submit the details for the project and then make payment. For whatever reason they're submitting details and then not following through with payment about 50% of the time. And then they'll follow up So, are you working on the project or what? and then I have to explain You never finished your order. They follow up with a Whoops, here ya go.



Unfortunately, I would chalk this up as marketing and web design 101. Rule #1, people are dumb. Not to be taken in a rude or pessimistic sense. Basically, the idea is assume everyone is dumb in your design, instruction so that you make something so easy a five-year-old can do it. I totally agree with not holding users hostage. But this page is ONLY reached in the middle of their intended order process that THEY initiate (this page will never be reached in a browsing sort of way). So I think it's a pretty legitimate use case where you're saving a common user mistake from themselves. A demographic of customers that are not tech-savvy, so they honestly need such guidance.


More From » onclick

 Answers
44
document.querySelector('.eStore_buy_now_button').addEventListener(click, function(){
window.btn_clicked = true; //set btn_clicked to true
});

window.onbeforeunload = function(){
if(!window.btn_clicked){
return 'You must click Buy Now to make payment and finish your order. If you leave now your order will be canceled.';
}
};


This will alert the user whenever the page unloads (eg leaving the page) until btn_clicked is set to true.



DEMO: http://jsfiddle.net/DerekL/GSWbB/show/


[#84847] Friday, June 15, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
saulthomasb

Total Points: 326
Total Questions: 98
Total Answers: 93

Location: Jordan
Member since Sun, Dec 26, 2021
2 Years ago
;