? Which Link was clicked inside iframe?

Hello ,
This which-link-was-clicked .js works great :slight_smile:

<script>
	var links = document.querySelectorAll( 'a' );
	for ( var c = 0; c < links.length; c ++ ) {
         links[c].addEventListener('click', WhichLinkWasClicked);
      }
function WhichLinkWasClicked(evt) {
    alert( evt.target ) ; 
    evt.preventDefault();
		}
</script>

And now I need to apply it to an iframe . But so far I am able to do so . Can’t figure out which parameters go where .

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Opening Links in an iFrame</title>
	<style>
		iframe {
			width: 100%;
			height: 500px;
		}
	</style>
</head>
<body>
    <p><a href="file:///C:/Electron-js/___KidSafeBrowser-020121/main-Child/Frames-Study/Open-Links-In-iFrame.html" target="myFrame">Frames Study</a></p>
    <iframe src="file:///C:/Electron-js/___KidSafeBrowser-020121/main-Child/Frames-Study/SomeLocalLinks-00.html" name="myFrame"></iframe>
	
<script>
	var links = myFrame.document.querySelectorAll( 'a' );
	for ( var c = 0; c < links.length; c ++ ) {
         links[c].addEventListener('click', WhichLinkWasClicked);
      }
function WhichLinkWasClicked(evt) {
    alert( evt.target ) ; 
    evt.preventDefault();
		}
</script>
</body>
</html>

Thanks for your Help…

6 posts were merged into an existing topic: ? Detect which link was clicked inside <iframe>?