0

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.

totoaussi
  • 712
  • 1
  • 11
  • 27
  • "it doesn't work" — What does it do? Does it throw an error? – Quentin Jul 20 '15 at 11:16
  • Thank you for this. I try all the solutions on the topic, and i notice that cross-domain is not supported unfortunatly. My aim is to get the url clicked of a adsense ads beacause adsense ads are in iframes (I try to make a tracking script). – totoaussi Jul 20 '15 at 11:48
  • Tracking what people did on other people's websites would be a serious privacy and security risk, so it isn't possible without the explicit co-operation of the site you want to perform the tracking on. – Quentin Jul 20 '15 at 12:12

0 Answers0