I want to open a alert box when a certain link is clicked. How to do that ?
How to open a alert box within anchor tag <a href>?
Asked Answered
What do you mean by "pop up"? –
Mosstrooper
possible duplicate of javascript popup alert on link click –
Wateriness
You can also use the following codes:
<a href="#" id="link">Link</a>
Javascript:
$(document).on("click","#link",function(){
alert("I am a pop up ! ");
});
OR:
<a href="#" onclick="alert('I am a popup!');">Link</a>
Without using a JS file (purely as an alternative to answers already posted):
<a href="http://example.com" onclick="alert('Hello world!')">Link Text</a>
<a href="#" onclick="myFunction(); return false;">
The return false;
will stop the web page being loaded after clicking.
JavaScript code:
function myFunction() {
alert("I am a pop up ! ");
}
The following code might help:-
<a id="anchor">i am the anchor</a>
<div id="popup">this is a popup</div>
<script>
$(function(){
$('#popup').hide();
$('#anchor').click(function(){
$('#popup').show();
})
});
</script>
Simple JS payload with anchor tag when quotes are HTML encoded
<a href="javascript:alert(1)"> vish </a>
What’s the functional or practical difference between this and @Shuma’s previous answer? Please edit to clarify. –
Kondon
© 2022 - 2024 — McMap. All rights reserved.