Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow DOM location of iframe

    right, ive got my main page with an iframe on it. i want to change a div layer visibility depending on the location of the iframe (ie the url). im guessing i need to use DOM to find the location but im not too sharp on the ol' javascript! if someone could help me out id be v. grateful.
    Also, how can i get it too update if the location of the iframe changes?

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well if you assign the iFrame an id, then you can use document.getElementById() to retrieve it:
    Code:
     <iframe id="id_name" ...></iframe>
    
     ...
    
     <script>
      var i_frame = document.getElementById('id_name');
      alert(i_frame.getAttribute('src'));
     </script>
    So whatever id you assign to the iFrame, you need to use the same id to retrieve it using getElementById().

    Let me know how it goes,
    Sadiq.

  • #3
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeh ive done that. what ive got is

    document.getElementById(content).

    with content being the iframe id.

    but how do i find the src or location of the iframe? ie which page is displayed?

  • #4
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    whoop, sorry i didnt read your post properly (a little drunk!) thanx mate, ill give it a whirl

  • #5
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeh works a treat. but the problem is, how do i get it torefresh the variable once the page has changed inside the iframe?

    heres the bigger picture if it helps: ive got a nav bar, pointing at the iframe. ive then got a logo on the main page (same page as the nav bar) and my client wants the logo to change depending on the page displayed in the iframe! &$@*%!!! is there an easier way to go about this, or am i heading down the right road with javascript?

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes you can do this with Javascript.. depending..

    So when will the page within the iFrame get changed? Only when an item from the nav bar is selected, correct? Are there links in the pages within the iFrame? It might be tricky (I'm not sure if there's an event of some kind that you can handle for this..) if the page in the iFrame can change with the user needing to click on the main frame.

    If this is the case, it may be better to scrap the iFrame idea, and move to using a DIV and server side using includes (using PHP or something...). This will require the page to 'refresh' more, but you'll have better control over it.

    Sadiq.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •