另一种从html中的href标签调用javascript函数的方法

时间:2014-05-13 08:23:21

标签: javascript jquery google-analytics internet-explorer-9

我有这个代码,它在Chrome和Firefox上100%工作但不在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">

1 个答案:

答案 0 :(得分:1)

这是未经测试的。但是尝试为链接设置一个监听器,而不是在html中定义JS。 E.g。

<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>

然后你的HTML会是。

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