简体   繁体   中英

another way of calling javascript Function from href tag in html

I have this code and its working 100% on Chrome and Firefox but not working on IE 9.

 <script>
 $(document).ready(function() {
 _gaq.push(['_trackEvent', 'Revenues', '<?php echo $tracking_event; ?>']);
  });

<a href="javascript;" onclick="_gaq.push(['_trackEvent', 'social', 'share_fb']);
               window.open('https://www.facebook.com/sharer/sharer.php?
               u='+encodeURIComponent(location.href), 'facebook-share-dialog',
               'width=650,height=450');  return false;" class="os_new_icons_fb">

This is untested. But try setting a listener for the link instead of defining the JS within the html. Eg

<script>
   $('.my-class').click(function(e) {
      e.preventDefault();
      _gaq.push(['_trackEvent', 'social', 'share_fb']);
      window.open('https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href), 'facebook-share-dialog','width=650,height=450');
   });
</script>

And then your html would be.

<a href="#" class="my-class">CLICK HERE</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM