html onclick popup两次打开相同的链接

时间:2014-06-18 21:22:21

标签: html

此超链接按预期运行,但我需要弹出窗口:

<a href="videochat.php?invite={sn_im_chatbox.USERNAME_TO}" class="sn-tooltip" title="Video Chat"><span class="ui-icon sn-im-cbVideochat"></span></a>    

我尝试了以下操作,但它更改了页面(如上所示)并打开弹出窗口(按预期)。知道如何防止它两次执行相同的功能吗?

<a href="videochat.php?invite={sn_im_chatbox.USERNAME_TO}" onclick="popup(this.href, 750, 500); return false;" class="sn-tooltip" title="Video Chat"><span class="ui-icon sn-im-cbVideochat"></span></a>

2 个答案:

答案 0 :(得分:0)

而不是return false;处理程序中的onclick使用event.preventDefault()

<a href="videochat.php?invite={sn_im_chatbox.USERNAME_TO}" 
  onclick="popup(this.href, 750, 500); event.preventDefault();" 
  class="sn-tooltip" title="Video Chat">
    <span class="ui-icon sn-im-cbVideochat"></span>
</a>

这可能会妨碍浏览器在JavaScript可用时常规打开链接。

答案 1 :(得分:-1)

您只需将网址放入onclick并将href属性设置为#javascript:void(0)

<a href="#" onclick="popup('videochat.php?invite={sn_im_chatbox.USERNAME_TO}', 750, 500); return false;" class="sn-tooltip" title="Video Chat"><span class="ui-icon sn-im-cbVideochat"></span></a>

<a href="javascript:void(0)" onclick="popup('videochat.php?invite={sn_im_chatbox.USERNAME_TO}', 750, 500); return false;" class="sn-tooltip" title="Video Chat"><span class="ui-icon sn-im-cbVideochat"></span></a>