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 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Just need a little extra to make this iframe refresh just once...

    Hi--

    I have found a neat trick to refresh an iframe in an html page, but I just need one little twist to make it work just right. I would like to make the iframe content refresh just once, not matter how many times the link is clicked...

    Right now, I have this in the head:
    <script type="text/javascript">
    function refreshIframe(el) {
    var f = document.getElementById(el)
    var rsrc = f.src
    f.src="about:blank"
    f.src=rsrc
    }
    </script>
    And this is the link which, when clicked, refreshes the iframe every time it is clicked:
    <a href="#page_7c" onclick="refreshIframe('test'); return false">
    "test" is the id of the iframe.

    I am sure how to do this is really simple, but it escapes me... Many thanks!

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,980
    Thanks
    56
    Thanked 557 Times in 554 Posts
    here's a cheap and nasty way to do it...

    Code:
    var a=0;
    function refreshIframe(el) {
    if(a==0){
    var f = document.getElementById(el)
    var rsrc = f.src
    f.src="about:blank"
    f.src=rsrc
    }
    a=1;
    }

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Works like a charm. Many thanks!!!!

  • #4
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Self-cancelling handler:
    Code:
    <a href="#page_7c" onclick="refreshIframe('test'); this.onclick = function(){ return false; }; return false">

  • #5
    New Coder
    Join Date
    Aug 2011
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This also does the trick. Thanks!


  •  

    Posting Permissions

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