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 12 of 12
  1. #1
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Question Any methods to refresh a div or iframe?

    Is there any method to refresh a div or an iframe from a popup window when the popup opens and or closes?

    Cheers
    Last edited by student101; 08-05-2008 at 06:05 PM.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #2
    Regular Coder
    Join Date
    Mar 2008
    Posts
    301
    Thanks
    2
    Thanked 30 Times in 30 Posts
    "refresh"? You want to reload an iframe, or just alter the content?

    You can reload the iframe by setting a new URL to the iframe's "src" property.

    You can alter the content by getting a handle/reference to the iframe:

    Code:
    	function IFRloc(strIdIframe){
    		var targFram = top.document.getElementById(strIdIframe);
    		var r = targFram.contentDocument ? targFram.contentDocument : (targFram.contentWindow ? targFram.contentWindow.document : self.frames[mapLinkTarg].document);
    		return r;
    	};
    Then using that object that's returned by the function, above, make changes to the document (if it's from the same server as the parent document).

  • #3
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by fside View Post
    "refresh"? You want to reload an iframe, or just alter the content?
    You can reload the iframe by setting a new URL to the iframe's "src" property.
    You can alter the content by getting a handle/reference to the iframe:
    Code:
    function IFRloc(strIdIframe){
    var targFram = top.document.getElementById(strIdIframe);
    var r = targFram.contentDocument ? targFram.contentDocument : (targFram.contentWindow ? targFram.contentWindow.document : self.frames[mapLinkTarg].document);
    return r;
    };
    Then using that object that's returned by the function, above, make changes to the document (if it's from the same server as the parent document).
    Refresh.

    Wow, that looks good, let me drop my code in with it to see how this could work;

    Code:
    strIdIframe = iframe id; like <iframe id="strIdIframe"></iframe>
    contentDocument = parent.php
    contentWindow = child.php
    mapLinkTarg = what is this one for?

    Is this right?
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #4
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    Anyone able to help me decode this code that was posted?
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #5
    Regular Coder
    Join Date
    Mar 2008
    Posts
    301
    Thanks
    2
    Thanked 30 Times in 30 Posts
    May have copied from the wrong library:

    Code:
    	functionIFRcontent(ifrId) {
    		var ifr = top.document.getElementById(ifrId);
    		if (ifr){ return ifr.contentDocument ? ifr.contentDocument : (ifr.contentWindow ? ifr.contentWindow.document : self.frames[ifrId].document);
    		} else {
    			return null;
    		}
    	}
    So - var hIFR = IFRcontent("strIdIframe")

    And hIFR.getElementById("someid"), gets you inside the iframe from code running outside.

  • #6
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Question

    Quote Originally Posted by fside View Post
    May have copied from the wrong library:
    Code:
    function IFRcontent(ifrId) {
    var ifr = top.document.getElementById(ifrId);
    if (ifr){ return ifr.contentDocument ? ifr.contentDocument : (ifr.contentWindow ? ifr.contentWindow.document : self.frames[ifrId].document);
    } else {
    return null;
    }
    }
    So - var hIFR = IFRcontent("strIdIframe")
    And hIFR.getElementById("someid"), gets you inside the iframe from code running outside.
    Cool thanks! do I post this in the child.php or parent.php?
    Also do I use both of them or just the last one you posted and do I change it up to fit my needs as in div ids and so on?

    parent.php
    PHP Code:
    <iframe src="about:blank" name="myframeid" width="120" height="120" scrolling="no" frameborder="0" ></iframe
    child.php
    PHP Code:
    <script language="JavaScript" type="text/javascript">
    function 
    IFRcontent(ifrId) {
    var 
    ifr top.document.getElementById(ifrId);
    if (
    ifr){ return ifr.contentDocument ifr.contentDocument : (ifr.contentWindow ifr.contentWindow.document self.frames[ifrId].document);
    } else {
    return 
    null;
    }
    }
    </script>
    <body onload="IFRcontent('myframeid');"> 
    Am I close or is there something wrong here?
    Last edited by student101; 08-05-2008 at 11:10 PM.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #7
    Regular Coder
    Join Date
    Mar 2008
    Posts
    301
    Thanks
    2
    Thanked 30 Times in 30 Posts
    Well, it was assuming you're running code in the 'parent', and accessing the child iframe. The child.php is the one in the iframe, correct?

    I also assumed there was more script to it. So this one little function would go in your larger script, whether you have that hard-coded into the 'parent', or whether an external js file.

    And just call the function with the id of your iframe, save the reference it returns, and you can access elements inside the iframe, running code from the 'parent'.

    I've done this, myself, taking older pages that are loaded into an iframe, and removing the navigation pane and some particular links which shouldn't be clicked if displayed in a frame.

  • #8
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Post

    Well, it was assuming you're running code in the 'parent', and accessing the child iframe. The child.php is the one in the iframe, correct?.
    Yes with the <a href="child.php">child page</a>, but the child.php is not in the iframe - it could be any file.
    just call the function with the id of your iframe, save the reference it returns, and you can access elements inside the iframe, running code from the 'parent'.
    I get this; <body onload="IFRcontent('myframeid');"> this would go in child.php in order to refresh the iframe in parent.php.

    ==============

    Let me try to explain;
    I have parent.php that has an iframe (mylist) which has a link to another page.
    The link should only appear if there is data for that $ipaddress, hence the refresh of the iframe (mylist).

    The iframe (mylist) has this;
    PHP Code:
    <?php $ipaddress getenv('REMOTE_ADDR');
    if (
    $rswish 0) { // Show if not empty ?>
    <a href="mylist.php?name=<?php echo $ipaddress?>My list</a>
    <?php // Show if not empty ?>
    To produce rswish;
    PHP Code:
    SELECT *
    FROM table
    WHERE name 
    '$ipaddress' 
    Currently I am forced to refresh the entire page to get this link to show.
    I hope this can help you understand what I need?
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #9
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    I may have solved it! YIPPPEEEEEE!!!

    In the iframe I add this;
    Code:
    <meta http-equiv="refresh" content="6">
    So every 6 seconds the iframe refreshes to see if the data is allowed to be shown.

    Why didn't I see this earlier! dam&it!

    I see it keeps refreshing even when it's loaded;
    Is there a way to do this?
    Code:
    if (parent.frames['myframeid'].src != 'mypage.php'){ 
     - run the refresh script till it does show up then stop refreshing 
    }
    Cheers
    Last edited by student101; 08-06-2008 at 11:15 AM.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #10
    Regular Coder
    Join Date
    Mar 2008
    Posts
    301
    Thanks
    2
    Thanked 30 Times in 30 Posts
    That's very different than trying to manipulate the contents of the iframe from the 'parent' document.

    But if you need to update the entire page, a constant 5-6 second page reload might not be recommended.

    Why do you think you need to do this? If it's some sort of old-style client-pull, are you doing this for fear users won't have javascript enabled?

  • #11
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    No, let me try and explain what it is that I am trying to achieve.

    In the parent.php i have a two links Add and View
    Clicking Add will add a record to the table, by opening a popup and closes it.
    Clicking View will view the record that was added, based on the ip address of the user.

    The view link must only be available once a record is added.

    I was unable to do this from a popup and divs so I resorted to refreshing the entire page when the popup closed which also lost my content that I was viewing.
    Then I tried iframes and this worked as it kept my content available and only refreshed the iframe.

    I'm not really interested whether users have javascript enabled or not.

    Hope that makes sense.
    Last edited by student101; 08-06-2008 at 11:43 AM.
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:

  • #12
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts

    Question

    How to make this work?

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml" lang="pl" xml:lang="pl">
    <
    head>
    <
    title>iframe reload</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <
    script type="text/javascript">


    //THIS PART BREAKS and doesn't work, how to fix?

    //if(window.frames.reloader.src == "http://www.google.com/"){

    //END THIS PART BREAKS


    // set your interval in milliseconds
    var reloadInterval 3000;
    // this will run when the document is fully loaded
    function init() {
     
    setTimeout('reload()',reloadInterval);
    }
    // this reloads the iframe, and triggers the next reload interval
    function reload() {
     var 
    iframe document.getElementById('reloader');
     if (!
    iframe) return false;
     
    iframe.src iframe.src;
     
    setTimeout('reload()',reloadInterval);
    }
    //}
    // load the init() function when the page is fully loaded
    window.onload init;
    -->
    </script>
    </head>
    <body>
    <iframe id="reloader" width="500px" height="400px" src="http://www.google.com/"/>
    </body>
    </html> 
    Thanks for your support!
    Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

    Give thanks & resolve when done :thumbsup:


  •  

    Posting Permissions

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