1

I have a page which contains a Iframe. And i have opened an external website in that iframe.I want to capture the exact link which is clicked inside the iframe using pure Javascript. Below is my iframe code.

<iframe id = "frame" src="" name="iframe_a" width = 100% height = 100% style="border:none;""> </iframe>

 

var monitor = setInterval(function()
{
var elem = document.activeElement;
if(elem && elem.tagName == 'IFRAME')
 {
    elem.blur();
    console.log(iframe_a.href);
  //console.log("clicked");
}
  }, 100);
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 2
    Possible duplicate of [Detect click event inside iframe](https://stackoverflow.com/questions/13439303/detect-click-event-inside-iframe) – An0num0us Aug 30 '18 at 07:23

1 Answers1

-1
document.getElementsByTagName("a").forEach(function(el){
     el.addEventListener("click", function(el){
         //here is your link value
         var link = el.currentTarget.getAttribute('href');
         //return false;
     });
});
Ruboss
  • 64
  • 1
  • 7