Dumb question about links and iframes

Discussion in 'HTML & Website Design' started by jnestor, Jun 29, 2006.

  1. #1
    There's a page on another site - it's normally in a pop-up window - that contains an iframe and some links. The links target the iframe such that selecting a link just changes the content in the ifram rather than loading a whole new page.

    There's no way to link to that page in such a way that it would load the contents of specific link in the iframe is there? I don't think there is but it seems like there should be :)

    
    <iframe src="default.html" name="inner">
    </iframe>
    <a href="another.html" target="inner">Another</a>
    <a href="yet-another.html target="inner">Yet Another</a>
    Code (markup):
     
    jnestor, Jun 29, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    link to it like page.php3?frame=another.html and then load the appropriate frame.

    However if you are doing it this way then you may as well not use iframes.
     
    mad4, Jun 29, 2006 IP
  3. jnestor

    jnestor Peon

    Messages:
    133
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I don't control the page. It's on another site. Basically it's a pop-up "mini site" that shows a video in an iframe and has links to select other videos. I'm linking to it from an external site and want to be able to select which video plays. I can play the video directly outside of the "mini site" but that's not ideal.
     
    jnestor, Jun 29, 2006 IP
  4. brian394

    brian394 Well-Known Member

    Messages:
    226
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Well, you have a number of options.

    1.) You could link to "another.html" directly which would bring the user directly to the video (but in that case they wouldn't see any links to the side (for the other videos), and it may look rather akward (depending on how this external site has laid out their iframe).

    or

    2.) You can also do it with javascript. I'm assuming your using the window.open() function on your own site to open the pop-up. Well, as you may remember the window.open() function returns a reference to the newly opened window. You can then use this reference to affect elements on the newly opened page. In your case you would want to update the src (href) attribute of the IFRAME to the URL of your choice. Something like this (this would be the source code on your page)...

    
    <script type="text/javascript">
    var ref;
    function open_video_window() {
     ref = window.open("http://www.external-site.com/iframe_holder.html", "pop_up_win", "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
     if (ref !== null) { ref.onload = pop_up_onload; }
    }
    function pop_up_onload() {
     if (ref !== null) { ref.frames[0].location.href = "another.html"; }
    }
    </script>
    
    <a href="javascript:open_video_window()">Play Video</a>
    
    Code (markup):
     
    brian394, Jul 1, 2006 IP
  5. jnestor

    jnestor Peon

    Messages:
    133
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yeah, #1 is what I'm doing. #2 is what I want but I can't get the onload event to work. Can you really set an onload handler like this? I thought cross site scripting rules would prevent it? At any rate it's either not allowed or I'm doing something wrong. :)
     
    jnestor, Jul 5, 2006 IP
  6. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can't alter what happens on the other page unless they have installed a script to allow you to do it.
     
    mad4, Jul 5, 2006 IP