Jump to content

Example of: AddEventListener-For-A-Tag-Stop-Navigation .


vmars316
 Share

Recommended Posts

It took me a while , but here's the code;

<!DOCTYPE html>
<html>
<head>
<title> AddEventListener-For-A-Tag-Stop-Navigation </title>
<script>
function CreateJsListener() {
  document.querySelector('a').addEventListener('click', function(event) {Redirect(event) } )  } ;
</script>
</head>

<body onload="CreateJsListener()">


<a href="https://www.google.com"> https://www.google.com </a>

<script>
var timesThru = 0 ;
  
function Redirect(event) {
    event.preventDefault() ;
	window.open("NOT-A-SafeSite.html");
	timesThru = timesThru + 1 ;
   }
	
</script>

</body>
</html>

 

<!DOCTYPE html>
<html>
<head>
<title> NOT-A-SafeSite.html </title> 
</head>

<body>
<h4> The Link you clicked on is <span style="color: red">UNSAFE !</span> &nbsp; ....Navigation CANCELED. </h4>
</body>
</html>

Thank you  :)

 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...