title: How to prevent users to redirect to next page before the answer the question
body: <p>I would like the users to fill in the feedback form before they try to navigate away from the current page</p>
  <p>I added following code in angular</p>
  <pre><code>            link: function(scope, element, attrs) {
              if (window.addEventListener) {
  
                  window.addEventListener(&quot;beforeunload&quot;, function(){         
                              scope.showForm = true;
                   });
              } 
  </code></pre>
  <p>It shows the form but the page gets redirect to the next page (I mean, to the page the user has clicked link on).</p>
  <p>If I add <code>event.returnValue=&quot;something&quot;</code> it works, but then first it shows the alert and then it shows the custom form. I have tried</p>
  <code>
  <pre><code>    $scope.$on('$locationChangeStart', function( event ) {
                  var answer = confirm(&quot;Are you sure you want to leave this page?&quot;)
                  if (!answer) {
                      event.preventDefault();
                  }
              });
  </code></pre>
    </code>
  <p>but this doesn't work as well.</p>
  <p>Please help how can I show the form, prevent redirect without alerT?</p>