user3103783
user3103783

Reputation: 175

JS not function in Firefox

I tries to used this code to make an alert when user click on the link. However, this function only work with Chrome and Internet Explorer but doesn't work in Firefox.

Please refer to the code below :

jQuery(function($) {
  $(document).ready(function() {
    $(".disableGA").on("click", function() {
      event.preventDefault();
      alert("Google Analytics was disabled");
      window.location.href = 'javascript:gaOptout()';
    });
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="disableGA">Disable Google Analytics</a>

Upvotes: 0

Views: 89

Answers (1)

Nandita Sharma
Nandita Sharma

Reputation: 13417

Please pass event to the function and try again

<script>
jQuery(function ($) {
$( document ).ready(function() {
    $(".disableGA").on("click", function(event){
        event.preventDefault();
        alert("Google Analytics was disabled");
        window.location.href='javascript:gaOptout()';
    });
}); 
});
</script>

Upvotes: 4

Related Questions