2013-01-10 37 views
-1

我已经放在一个onClick goconfirm上的超链接按照以下:的JavaScript的onClick确认没有发射

<a href="http://google.com" onclick="goConfirm('This link is to an external site. You are now 
leaving mysite.,'href=http://google.com');' target="_blank">Online Account Opening</a> 

如何确保确认JavaScript消息触发发送用户到新的站点之前?

非常感谢您的帮助和指导。

+0

您可以显示'goConfirm'的代码? –

+3

你在第一个参数结尾缺少''''。另外,在属性值的末尾有一个''',而不是''',用于启动该值。 – Sampson

+3

请检查控制台! – Ryan

回答

5

您不以任何方式阻止默认操作。试试这个:

<a href="..." onclick="return confirm('This link is... ');">...</a> 

或者,如果goConfirm实际上是你的一个功能,你应该添加return false;到的onclick结束。

而且修正不匹配的报价;)

2

我想这是一个错字。试试这个:

<a href="http://google.com" onclick="goConfirm('This link is to an external site. You are now leaving mysite.','href=http://google.com');return false;" target="_blank">Online Account Opening</a> 

我还会在最后加了return false,以确保当前网页不会被重定向。

0

,这样它会等待,直到你确认你应该删除代码从锚标记的JS函数打开新的一页。

<script> 
function goConfirm(message, url) { 
    var choice = confirm(message); 
    if (choice) { 
    window.open(url, "_blank"); 
    } 
} 
</script> 
<a href="#" onclick="goConfirm('This link is to an external site. You are now leaving mysite.,\'href=http://google.com\'', 'http://google.com');">Online Account Opening</a> 

在菲德尔 - http://jsfiddle.net/poonia/2bYKV/

0

使用<a href="javascript:void(0)" onclick="return confirm('This link is... ');">...</a>以避免网址有任何变化