Tracking IFRAME URL

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]

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:


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…