cannot access links in an iframe

Discussion in 'Javascript' started by oscar1martin@gmail.com, May 30, 2007.

  1. Guest

    The property document.links seems to access links inside a frame, but
    not an iframe. For instance, the following code displays a "4": 2
    links in main page, 2 links in frame1.


    <body onload="fn()">
    <script type="text/javascript">
    function fn()
    {
    alert(document.links.length)
    }
    </script>

    <a href="http://somewhere1">aaa</a>
    <a href="http://somewhere2">bbb</a>

    <frameset>
    <frame name="frame1" id="frame1">
    <a href="http://somewhere3">ccc</a>
    <a href="http://somewhere4">ddd</a>
    </frame>
    <iframe name="frame2" id="frame2" src="http://somewhere5">
    </iframe>
    </frameset>

    </body>


    Is there a way to access the links in the iframe?

    Thanks in advance.
     
    , May 30, 2007
    #1
    1. Advertising

  2. -Lost Guest

    wrote:
    > The property document.links seems to access links inside a frame, but
    > not an iframe. For instance, the following code displays a "4": 2
    > links in main page, 2 links in frame1.
    >
    > <body onload="fn()">
    > <script type="text/javascript">
    > function fn()
    > {
    > alert(document.links.length)
    > }
    > </script>


    It reports exactly what is found. Now, whether or not you understand
    your markup is an entirely different thing.

    > <a href="http://somewhere1">aaa</a>
    > <a href="http://somewhere2">bbb</a>
    >
    > <frameset>
    > <frame name="frame1" id="frame1">
    > <a href="http://somewhere3">ccc</a>
    > <a href="http://somewhere4">ddd</a>
    > </frame>
    > <iframe name="frame2" id="frame2" src="http://somewhere5">
    > </iframe>
    > </frameset>
    >
    > </body>


    How do you expect JavaScript to behave the way you want it to if you do
    not provide it valid HTML?

    > Is there a way to access the links in the iframe?


    Yes. You must first however embed it properly in a page. For example,
    in a frame, in a frameset.

    --
    -Lost
    Remove the extra words to reply by e-mail. Don't e-mail me. I am
    kidding. No I am not.
     
    -Lost, May 30, 2007
    #2
    1. Advertising

  3. marsanos Guest

    Well, yes, I guessed I could be doing something wrong, but what is it?

    I have skimmed trhough hundreds of examples on the net and they all
    seem like mine to me.
    Also, the page displays correctly.

    Some more help, please?
     
    marsanos, May 30, 2007
    #3
  4. David Dorward, May 30, 2007
    #4
  5. marsanos Guest

    Now, this is a helpful answer. And a proof that there are a few things
    I have to learn.

    Thanks to both of you.
     
    marsanos, May 31, 2007
    #5
  6. RobC Guest

    David Dorward wrote:
    > ...
    > Avoid frames: http://allmyfaqs.net/faq.pl?Problems_with_using_frames
    >
    >

    I've seen warnings on Google's site about indexing problems when using frames.
    Although Google does seem to index pages using iframes without any problems as long
    as you provide non-iframe support information.

    Rob
    www.rcp.ca
     
    RobC, Jun 3, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.microsoft.com
    Replies:
    4
    Views:
    4,998
    =?Utf-8?B?Q2hpbm1heQ==?=
    Jan 10, 2005
  2. Ram
    Replies:
    2
    Views:
    7,237
    Paul Glavich [MVP ASP.NET]
    Jun 30, 2005
  3. Replies:
    0
    Views:
    518
  4. Daedalous
    Replies:
    3
    Views:
    753
    Daedalous
    Jan 16, 2004
  5. Replies:
    3
    Views:
    100
Loading...

Share This Page