簡體   English   中英

從HTML中的href標簽調用javascript函數的另一種方法

[英]another way of calling javascript Function from href tag in html

我有這段代碼,它在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">

這是未經測試的。 但是,請嘗試為鏈接設置偵聽器,而不是在html中定義JS。 例如

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM