admin管理员组文章数量:1318973
I've placed an onClick goconfirm on a hyperlink per below:
<a href="" onclick="goConfirm('This link is to an external site. You are now
leaving mysite.,'href=');' target="_blank">Online Account Opening</a>
How do I ensure the confirmation Javascript message fires before sending the user to the new site?
Thanks much for your help and guidance.
I've placed an onClick goconfirm on a hyperlink per below:
<a href="http://google." onclick="goConfirm('This link is to an external site. You are now
leaving mysite.,'href=http://google.');' target="_blank">Online Account Opening</a>
How do I ensure the confirmation Javascript message fires before sending the user to the new site?
Thanks much for your help and guidance.
Share Improve this question asked Jan 10, 2013 at 3:34 SidCSidC 3,21315 gold badges74 silver badges139 bronze badges 3-
Can you show the code in
goConfirm
? – Joseph Silber Commented Jan 10, 2013 at 3:35 -
3
You're missing a
'
at the end of your first argument. Additionally, you have a'
at the end of the attribute value instead of a"
, which was used to start the value. – Sampson Commented Jan 10, 2013 at 3:35 - 3 Check the console, please! – Ry- ♦ Commented Jan 10, 2013 at 3:36
4 Answers
Reset to default 5You are not preventing the default action in any way. Try this instead:
<a href="..." onclick="return confirm('This link is... ');">...</a>
Or if goConfirm
is actually a function of yours, you should add return false;
to the end of the onclick.
Also fix the mismatched quotes ;)
I guess it was a typo. Try this instead:
<a href="http://google." onclick="goConfirm('This link is to an external site. You are now leaving mysite.','href=http://google.');return false;" target="_blank">Online Account Opening</a>
I also added a return false
at the end to ensure the current web page won't be redirected.
You should remove the code to open the new page from the anchor tag to the JS function so that it waits till you confirm.
<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.\'', 'http://google.');">Online Account Opening</a>
Fiddle at - http://jsfiddle/poonia/2bYKV/
use <a href="javascript:void(0)" onclick="return confirm('This link is... ');">...</a>
to avoid any change in url
本文标签: htmlJavascript onClick confirm not firingStack Overflow
版权声明:本文标题:html - Javascript onClick confirm not firing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742056721a2418339.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论