Getting frame/iframe urls with javascript?

Discussion in 'JavaScript' started by redhits, May 15, 2010.

  1. #1
    How i can get an frame "current" url or an iframe url with javascript?
     
    redhits, May 15, 2010 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #2
    .location property
    on a normal page it is document.location
    on frames frames['xxx'].location
     
    gapz101, May 15, 2010 IP
  3. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #3
    I really don't know why this code is not working...
    
    
    <script type="text/JavaScript">
    
    function geturl(){
    var url=document.getElementById("active").src;
    document.getElementById("status").innerHTML=url;
    alert(url);
          }
    
    </script>
    
    
    
    
    <div class=status id=status>Start Surfing...</div>
    <script type="text/JavaScript">
    geturl();
    </script>
    
    <iframe id="active" src="http://www.google.com" border=0 height=500 width=100%>
    
    Code (markup):
     
    redhits, May 18, 2010 IP
  4. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #4
    Actually the Javascript is not seeing my IFRAME "active"

    if i am doing an document.getElementById("active").style.display="none"; will not hide it, but if i will do an document.getElementById("status").style.display="none"; it will hide the status DIV...


    Also things like window.frames[active].location='http://yahoo.com'; , will just not work...
     
    redhits, May 18, 2010 IP