Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 245 characters in body
Source Link
Mitch Dempsey
  • 40.3k
  • 6
  • 72
  • 75
<a href="google.com" target="_blank" onclick="javascript:alert('Navigation Prevented');return false;">CLICK HERE FOR GOOGLE</a> 

The important part of this is the return false; on the onclick attribute. This instructs the browser to immediately cancel this link after clicking. So what will happen is the javascript will be executed, but the link will not be followed.

<a href="google.com" target="_blank" onclick="javascript:alert('Navigation Prevented');return false;">CLICK HERE FOR GOOGLE</a> 
<a href="google.com" target="_blank" onclick="javascript:alert('Navigation Prevented');return false;">CLICK HERE FOR GOOGLE</a> 

The important part of this is the return false; on the onclick attribute. This instructs the browser to immediately cancel this link after clicking. So what will happen is the javascript will be executed, but the link will not be followed.

Source Link
Mitch Dempsey
  • 40.3k
  • 6
  • 72
  • 75

<a href="google.com" target="_blank" onclick="javascript:alert('Navigation Prevented');return false;">CLICK HERE FOR GOOGLE</a>