My iframe contains a simple webpage called (page.html) where the source code is just :
<html>
<head>
</head>
<body>
<a href="http://localhost/"></a>
</body>
</html>
And in the page which contains the iframe, i want the javascript code to get the url (the href) of the clicked link in iframe.
My current code of the parent page is the follow :
<html>
<head>
</head>
<body>
<iframe id="iframe" src="page.html"></iframe>
<script type="text/javascript">
document.getElementById("iframe").contentDocument.addEventListener("click",
function(event)
{
event = window.event || event;
console.log(event.target.href);
},
false
);
</script>
</body>
</html>
=> but it doesn't work.
Have you an idea ?
Thank you in advance, cordially.