# Tracking IFRAME URL

**URL:** <https://forum.kirupa.com/t/tracking-iframe-url/264779>\
**Category:** Uncategorized\
**Created:** [June 30, 2008, 1:58pm UTC](https://forum.kirupa.com/t/tracking-iframe-url/264779 "2008-06-30T13:58:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pandu\_kirupa](https://avatars.discourse-cdn.com/v4/letter/p/cab0a1/32.png) [@pandu\_kirupa](https://forum.kirupa.com/u/pandu_kirupa)\
**Post date:** [June 30, 2008, 1:58pm UTC](https://forum.kirupa.com/t/tracking-iframe-url/264779/1 "2008-06-30T13:58:44Z")

</div>

Hi all,

```
    I am using an IFRAME in which I am passing different URL's from flash and it is loading fine.  

```

But, once the URL is loaded in to that IFRAME, I need to track user clicks on this IFRAME and should send the user clicked URLs to Flash.

[COLOR=Red]Could anybody please tell me how could I track the currently loaded URL in IFRAME.

[COLOR=Black]I wrote an [COLOR=Red]onload [/COLOR]function which checks for the [COLOR=Red]src [/COLOR]element of IFRAME. But later i found its just a setting value, means if a user clicks a URL in IFRAME, the [COLOR=Red]src [/COLOR]wouldn’t change and giving me the URL which I had set initially.

my another problem is:  
[COLOR=Red]Could anybody pls tell me how the subsequent URLs in IFRAME should load in that IFRAME only and not in whole document. [/COLOR]

How can i do this.

Thanks in advance  
pandu  
[/COLOR][/COLOR]

---

<div class="post-metadata">

**Author:** ![jwilliam](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jwilliam](https://forum.kirupa.com/u/jwilliam)\
**Post date:** [June 30, 2008, 3:17pm UTC](https://forum.kirupa.com/t/tracking-iframe-url/264779/2 "2008-06-30T15:17:43Z")

</div>

One method is to add event listeners to your anchors that fire a javascript function to update the src attribute of you iframe. For example:

```auto

var links = document.body.getElementsByTagName('a');
for(var i = 0; i < links.length; i++) {
  addEvent(links*, 'click', function() { document.getElementById('iframe').src = this.href; }, true);
}

function addEvent(o, type, func, prop)
{

  if(!o) {
    return;
  }

  if (!document.addEventListener && document.attachEvent) {
    o.attachEvent("on" + type, func);
  } else {
    o.addEventListener(type, func, prop);
  }

}

```

You’d have to run that after the page is fully loaded. I didn’t test that code, so just use it as an example…
