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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with an Iframe

    Right, i've got a website up which contains an iframe (id is main) in which all the pages are loaded. On my parent page, I have an image. What code can I use such that when I click on that image, whatever page is currently in the iframe is opened in a new window.

    Thanks in advance.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    function doOpen(){
      var w = window.open(document.getElementById("main").src, "mypopup");
      w.focus();
      return false;
    }
    ...
    <a href="#" onclick="return doOpen()"><img src="open.gif" /></a>
    If document.getElementById("main").src doesn't work, try replacing it with:

    document.getElementById("main").contenWindow.location.href
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmmmm...

    The code manages to open a new window, but it only opens the default page of the iframe regardless of what page is currently loaded into it.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Did you try the second suggestion that uses contentWindow?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, the second one gives me an error:

    'document.getElementById(...).contenWindow.location' is null or not an object

  • #6
    Regular Coder
    Join Date
    Nov 2004
    Location
    The land of chocolate
    Posts
    226
    Thanks
    1
    Thanked 16 Times in 16 Posts
    Quote Originally Posted by Dragunov
    Yeah, the second one gives me an error:

    'document.getElementById(...).contenWindow.location' is null or not an object
    That's because it is contentWindow

    (glenn made a typo)

    The src property returns the src given by default in the code, that is why it always returns the default page, by the way. ContentWindow should work.
    -Snow

    Susie, if you want to see your doll again, leave $100 in this envelope by the tree out front. Do NOT call the police. You CANNOT trace us. You CANNOT find us.

    Sincerely,
    - Calvin.

  • #7
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ack, how silly of me. I should have noticed that.

    Thanks, both of you.

    btw, is there anyway I can make the new window pop up maximised?

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by snowieken
    That's because it is contentWindow

    (glenn made a typo)
    Oopps...Sorry about that.

    Here's the code to maximize the popup window:
    Code:
    function doOpen(){
      var w = window.open(document.getElementById("main").contentWindow.location.href, "mypopup", 'resizable=1, left=0, top=0, width='+screen.availWidth+', height='+screen.availHeight);
      w.focus();
      return false;
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #9
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It all works. Thank you.


  •  

    Posting Permissions

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