SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to refresh frame from another frame?

    Hello guys,

    I've googled for it and found solution, but it doesn't work:

    parent.frames[0].window.location.href=parent.frames[0].window.location.href
    How can I refrsh frame from another frame?

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you know the frame id, you can use

    Code:
    document.getElementById('frameid').history.go(-1);
    //or
    document.getElementById('frameid').location = document.getElementById('frameid').location;
    that should work, hth


  3. #3
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for reply.

    Yes, I know the Id of the frame. I've tried it in my code:

    function start()
    {
    document.getElementById('waitImage').src='$photoUploadedUrl'
    document.getElementById('photoFrame').location = document.getElementById('photoFrame').location
    document.write('done')
    }
    I call this function by <body onload="start()">

    This code doesn't work. Is there a mistake in my code?

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, calling it from body onLoad is not a good way to do it for two reasons

    1. The document doesn't know what or where your frames are as it is a linear procession.

    your asking it to run code on something that hasn't even been parsed yet.

    2. It is not unobtrusive, it is always bad to add javascript into your page, you should have it in your JS file only!


    But the simplest solution to this is add

    Code:
    <script>
    window.onload.start();
    </script>

    To the script section in that page or your external JS file



    I recommend you read about, unobtrusive javascript, addEvent, window.onload, Dean Edwards solution is by far the best. Pasted belkow for you

    Code:
    // Onload unobtrusive handler
    // Dean Edwards/Matthias Miller/John Resig
    
    /* for Mozilla/Opera9 */
    if (document.addEventListener) {
    	document.addEventListener("DOMContentLoaded", init, false);
    }
    
    /* for Internet Explorer */
    /*@cc_on @*/
    /*@if (@_win32)
    	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
    	var script = document.getElementById("__ie_onload");
    	script.onreadystatechange = function() {
    		if (this.readyState == "complete") {
    			init(); // call the onload handler
    		}
    	};
    /*@end @*/
    
    /* for Safari */
    if (/WebKit/i.test(navigator.userAgent)) { // sniff
    	var _timer = setInterval(function() {
    		if (/loaded|complete/.test(document.readyState)) {
    			init(); // call the onload handler
    		}
    	}, 10);
    }
    
    /* for other browsers */
    window.onload = init;
    
    function init() {
       start();
    }

  5. #5
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for tip. I plan to transfer all JS code to JS file when scripts will be completed.

    I've added line you wrote about, but it did not help.

    By the way, first line of start() function works even without "window.onload.start();". But 2 other lines do not work.

  6. #6
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well just don't use body.onload, it will cause no end of issues, good habits and all that

    Code:
    document.getElementById('photoFrame').location = document.getElementById('photoFrame').location
    That won't work because your calling your frame from another frame, so what the first frame is trying to do is make itself equal to its own loacation.


    You need to jump up a level. with window.

    I've got the code somewhere for this i will post it once i dig it up

  7. #7
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe this should work, works for me on one of my apps at work.

    Code:
    window.parent.document.getElementById('photoFrame').location = otherLocation;
    from my own experience with this it is the only thing that works on all browsers, parent.document, fails in some browsers, window.document can fail in others.

  8. #8
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I've inserted your code.

    Now, I can see only "done" words, printed by JS and nothing after it (all other HTML did not appear on the screen). Also, browser shows that something is loading all the time (I've waited like 2 minutes).

    Also, my JS debugger creates error "windows.onload.start is noa function".

  9. #9
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.write('done') will write what you tell it too, to the page, thats why you only see 'done'

    try removing it.

  10. #10
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by phrenetical View Post
    document.write('done') will write what you tell it too, to the page, thats why you only see 'done'

    try removing it.
    But it shouldn't affect all other code. Right?

    I'm totally confused with JS. When I fix some part of one function, another function stops working or part of another function stop working.

    I've added ";" symbols to every line and now all other HTML loads, but I don't see "done" message and also some parts of functions do not work now. It's so strange.

  11. #11
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've removed document.write and first line of function works. But second line (frame refreshing) doesn't work.

    function startScript()
    {
    document.getElementById('waitImage').src='$photoUploadedUrl';
    window.parent.document.getElementById('photoFrame').location = 'http://www.site.com';
    //document.write('done');
    }

  12. #12
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    windows.onload.start is wrong.

    it should be

    window.onload = start;


  13. #13
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    windows.onload.start is wrong.

    it should be

    window.onload = start;
    Still doesn't work. First line of startScript() function executes, but second line doesn't.

  14. #14
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    first line being?

    Code:
    document.getElementById('waitImage').src='$photoUploadedUrl';
    If so, I assume $photoUploadedUrl is a Server Side Variable, that contains the URL to the newly Uploaded image. If so, is it being displayed correctly?

    Could you possibly paste the parsed portion of the script? ie, run it in your browser, View the Source and copy the list within the source.


  15. #15
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    If so, I assume $photoUploadedUrl is a Server Side Variable, that contains the URL to the newly Uploaded image. If so, is it being displayed correctly?

    Could you possibly paste the parsed portion of the script? ie, run it in your browser, View the Source and copy the list within the source.
    Yes, it's PHP and url displayed correctly.

    Code from browser.

    <SCRIPT LANGUAGE="JavaScript" TYPE="TEXT/JAVASCRIPT">
    <!--

    window.onload = function() {
    var frm = document.getElementById("photoForm");
    frm.onsubmit = function() {
    document.getElementById('waitImage').src='http://www.example.com/img/wait.gif';
    document.getElementById('photoSubmit').disabled = true;
    document.getElementById('photoSubmit').value='Uploading...';

    }
    }

    function imageChange()
    {


    }

    function startScript()
    {
    document.getElementById('waitImage').src='http://www.example.com/photos/1/12023.jpg';
    document.photoSubmit.reset();
    window.parent.document.getElementById('photoFrame').location = 'http://www.example.com';
    document.write('ok');
    }
    window.onload = startScript;
    //-->
    </SCRIPT>

  16. #16
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok first of all, you have two onload events, unless these are on two seperate pages these could cause problems.

    I've just read the full thread properly. It seems window.parent doesn't exist.

    Can you confirm window.parent actually exists.


  17. #17
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    ok first of all, you have two onload events, unless these are on two seperate pages these could cause problems.

    I've just read the full thread properly. It seems window.parent doesn't exist.

    Can you confirm window.parent actually exists.
    Do you mean does main frame exist? I have a page with a lot of code. Iside this page I have 2 frames. The code above is from second frame. The first frame is photoFrame (I'm trying to refresh this frame from second one).

  18. #18
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just a thought as the line in question (window.parent....) seems to be causing the page to stop. If you try this in Firefox you may be able to find the error.

    It could be better if you could provide a sample that we could look at.


  19. #19
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    just a thought as the line in question (window.parent....) seems to be causing the page to stop. If you try this in Firefox you may be able to find the error.

    It could be better if you could provide a sample that we could look at.
    I don't see error about window.parent in FireFox.

    I tried change window.parent to parent, but it doesn't work

    I also PMed you.

    By they way, how 2 onload events can affect page? I mean both functions work, but partially (some lines work, some don't).


Bookmarks

Posting Permissions

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