1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.
  2. Better Analytics for WordPress Get It Free

Auto Close an iFrame

Discussion in 'Programming' started by icey7, Apr 3, 2012.

  1. #1
    Hi

    I have a simple iframe, which I would like to close automatically after 30seconds. How would I do that ?

    Here is the iFrame im currently using
    <iframe src='http://www.google.com' width='700' height='700' frameborder='0' scrolling='no'>
    </iframe>

    Thankyou.
     
    Solved! View solution.
    icey7, Apr 3, 2012 IP
  2. #2
    Hi
    I don't know but google is not showing up when I use iframe, in my little script I used one of my sites

    here it is:

    <script>

    function check_if_open() {
    var t=setTimeout("closeIframe()",30000);
    }



    function closeIframe() {
    var iframe = document.getElementById('someid');
    iframe.parentNode.removeChild(iframe);
    }

    </script>



    <iframe id="someid" src="http://www.archevintes.com" width="700" height="700" frameborder="0" scrolling="no" onload="check_if_open()">
    </iframe>
     
    selen, Apr 3, 2012 IP
  3. icey7

    icey7 Member

    Messages:
    114
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #3
    Hi Thanks for the message

    This section does not seem to work, The iframe is blank.
    <iframe id="someid" src="http://www.archevintes.com" width="700" height="700" frameborder="0" scrolling="no" onload="check_if_open()">
    </iframe>

    Thanks
     
    icey7, Apr 3, 2012 IP
  4. icey7

    icey7 Member

    Messages:
    114
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #4
    Hi

    my bad, I missed a symbol. Your code works perfectly...

    Thankyou very much
     
    icey7, Apr 3, 2012 IP
  5. icey7

    icey7 Member

    Messages:
    114
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #5
    Hi

    One question,

    the above code works but the 30 second count down does not start until the iframe page has completely loaded.

    Is there anyway to make the count down start straight away, so the iframe will close in 30 seconds even if it has not fully loaded ?

    thankyou again
     
    icey7, Apr 3, 2012 IP
  6. selen

    selen Active Member

    Messages:
    523
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    68
    #6
    Try this

    <script>

    onload=function() {
    var t=setTimeout("closeIframe()",30000);
    }



    function closeIframe() {
    var iframe = document.getElementById('someid');
    iframe.parentNode.removeChild(iframe);
    }

    </script>



    <iframe id="someid" src="http://www.archevintes.com" width="700" height="700" frameborder="0" scrolling="no" >
    </iframe>
     
    selen, Apr 4, 2012 IP
  7. icey7

    icey7 Member

    Messages:
    114
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #7
    Hey

    This new code works perfectly.

    Thankyou
     
    icey7, Apr 4, 2012 IP
  8. A.G

    A.G Well-Known Member

    Messages:
    2,472
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    100
    #8
    I still don'y see any difference, the timer still start also after full iframe load, nothing change
    did i miss something
     
    A.G, Apr 6, 2012 IP
  9. icey7

    icey7 Member

    Messages:
    114
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #9
    Hi

    It mostly working for me, there is still about a 5 seconds delay, but that's close enough to my needs. If there is a solution to having no delay, that would be great.

    Thanks
     
    icey7, Apr 6, 2012 IP