JavaScript Leave Page Alert Unless Submit Button Clicked

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/

Answer:1

I have a leaflet.js map that has points and linestrings on it that come from an external JSON file. If I add: map.setView(new L.LatLng(0,0), 10); It will centre the map on the latitude and ...

I have a leaflet.js map that has points and linestrings on it that come from an external JSON file. If I add: map.setView(new L.LatLng(0,0), 10); It will centre the map on the latitude and ...

I have to create an interface similar to what http://www.madeiracloud.com provides for drawing a network architecture (for different purposes than what they are doing). Basically users should be able ...

I have to create an interface similar to what http://www.madeiracloud.com provides for drawing a network architecture (for different purposes than what they are doing). Basically users should be able ...

I'm having somewhat of an odd issue with trying to piece together a somewhat dynamic Google Maps display. I have overlays on a map that I would like to call a function when clicked. Initially I had ...

I'm having somewhat of an odd issue with trying to piece together a somewhat dynamic Google Maps display. I have overlays on a map that I would like to call a function when clicked. Initially I had ...

First of all look at this question. None of those libraries support Multigraphs (or Pseudographs ). I mean I can't generate graphs like this: Is there any jQuery plugin (or javascript library) out ...

First of all look at this question. None of those libraries support Multigraphs (or Pseudographs ). I mean I can't generate graphs like this: Is there any jQuery plugin (or javascript library) out ...