javascript - onclick event not firing based on boolean flag -


i'm working on code if user clicks on particular button, person not presented exit popup upon exiting page. way i'm doing setting flag whenever user clicks on button. however, code isn't working expected: popup loads whether or not button clicked. don't understand why.

edit: help!

<!doctype html> <html>     <head>         <title>test!</title>          <script>             var bool = false;             var config = new object();             config.surveyid = 3155031;             config.takesurveyurl = 'http://www.supporterfeedback.org/a/takesurvey';             config.windowpositionleft = 200;             config.windowpositiontop = 300;             config.home = 'http://www.surveyanalytics.com/';             config.isrighttoleft = false;             config.showfooter = true;              // document.getelementbyid("btn").onclick = function()             //      {             //          bool = true;             //      };              function flag() {                 bool = true;             }              if (!bool) {                 window.onbeforeunload = function () {                     qp_popupmain();                 };             }         </script>          <script language="javascript"             src="http://www.surveyanalytics.com//javascript/exitsurveyinvitation.js"             type="text/javascript"></script>         <noscript>              <a href="http://www.supporterfeedback.org/a/takesurvey?id=3155031">start survey</a>          </noscript>     </head>     <body>          <a href="http://google.com"><img id="btn" onclick="flag()"             src="http://kelowna.directrouter.com/~jeasprco/wp-content/uploads/2012/05/panicbutton2.png"/></a>          <p>hello, test!</p>      </body> </html> 

i think window.onbeforeunload = function () operating page loads, inside if(!bool) executing on button press.

try changing these 2 lines:

// var bool = false;

var bool;   

// if (!bool) {

if (bool == false) { 

Comments

Popular posts from this blog

json - Zend error Connection -

javascript - Trigger mouseenter when an animated element touches mouse -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -