surya sasidhar

surya sasidhar

  • NA
  • 15
  • 42.6k

How to get Url of the page which is in iframe?

Aug 28 2010 8:37 AM
hi,
   In my web application i am using iframe for displaying the sites.
now i want to get the url of the site which in iframe, i write the code for getting the url of the site which in iframe this is my code. i write javascript for fetching the url like..

 
      function getSrc()
       {
        var v= document.getElementById('myIframe').src;
    alert(v);
  }

 <a href="#" onclick="javascript:getSrc()">Get src</a>

it is working fine, but problem is for example in my iframe i am displaying one site like amazon.com , when i click on books in amazon it will redirect to another books page now i want to get the url of the current page (i.e., Books page in amazon).
my code always fetch the url of http://www.amazon.com. but i want to get the url of the current page when i click on books. how can i please help me. Thank you