SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 32
  1. #1
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    setTimeout not working.

    Sorry to start yet another thread about this, but I searched the forums and didn't really understand how all the previous setTimeout problem threads relate to my problem.

    Here's the code in the head:

    Code:
    		<script language="javascript">
    		<!--
    		function reloadOpener(){
    			setTimeout(doItNow,2000);
    		}
    		function doItNow(){
    			window.opener.location.reload();
    		}
    		//-->
    		</script>
    And there's a button in the body that says:

    Code:
    onClick="reloadOpener();"
    When I try it without the setTimeout function, the opener page reloads no problem. I just need it to wait a wee minute, but when the setTimeout is there, nothing happens. Ever.

    For the sake of completeness I have tried it with:

    Code:
    setTimeout("doItNow()",2000);
    and:

    Code:
    onClick="setTimeout('reloadOpener',2000);"
    but neither of them worked either.

    I hope that's clear to you - it isn't to me.

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this-
    Code:
    function doItNow(){
    	try{
    		window.opener.location.reload();
    		alert('window.opener.location.href='+window.opener.location)
    	}
    	catch(er){
    		alert('typeof window.opener.location'+ typeof window.opener.location)
    	}
    }

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    setTimeout

    If you try this do you get an alert?
    HTML Code:
    <script language="javascript" type="text/javascript">
    <!--
    function reloadOpener(){
    	setTimeout("doItNow()",2000);
    }
    function doItNow(){
    	alert("in doItNow. window.opener.location is: " + window.opener.location);
    	window.opener.location.reload();
    }
    //-->
    </script>

  4. #4
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    If you try this do you get an alert?
    No.

  5. #5
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mrhoo View Post
    try this-
    Code:
    function doItNow(){
    	try{
    		window.opener.location.reload();
    		alert('window.opener.location.href='+window.opener.location)
    	}
    	catch(er){
    		alert('typeof window.opener.location'+ typeof window.opener.location)
    	}
    }
    The form processed, but the opener page did nothing. No alerts. Nothing.

  6. #6
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function inaSecond(){
    	window.timer= setTimeout(function(){
    		var win= window;
    		while(win.opener)win= win.opener;
    		win.location.reload(true);
    	},1000)
    	
    }
    
    doItNow= inaSecond;
    // call doItNow() from the button

  7. #7
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No joy mrhoo. Same thing again: form processed but no reload of the opener page.

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    no alert

    If you are not seeing the alert, maybe
    window.opener.location
    is NULL? ie. are you opening your page with window.open()?
    Maybe it would work better using
    parent.refresh();
    instead?

  9. #9
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    If you are not seeing the alert, maybe
    window.opener.location
    is NULL?
    Could be. But then why would it work without the setTimeout?

    Quote Originally Posted by Mittineague View Post
    ie. are you opening your page with window.open()?
    Yes.

    Quote Originally Posted by Mittineague View Post
    Maybe it would work better using
    parent.refresh();
    instead?
    I'll give that a try. Won't be for at least 10 hours before I get to a computer.

    Thanks for your help.

  10. #10
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does the Error Console in Firefox say?

  11. #11
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to have to say this, but I didn't know there was such a thing.

  12. #12
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    parent.refresh();
    Afraid that doesn't work with or without the setTimeout.

  13. #13
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pepejeria View Post
    What does the Error Console in Firefox say?
    Got it installed. It says nothing. Brought up some css warnings in sites in other open tabs, but no errors or warnings for my page.

  14. #14
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    step back

    Just to make sure, does this give you both alerts?
    HTML Code:
    <script language="javascript" type="text/javascript">
    <!--
    function reloadOpener(){
    	alert("in reloadOpener");
    //	setTimeout("doItNow()",2000);
    	doItNow();
    	return;
    }
    function doItNow(){
    	alert("in doItNow");
    //	window.opener.location.reload();
    //	parent.refresh();
    	return;
    }
    //-->
    </script>
    After you click -> onClick="reloadOpener();"

  15. #15
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. Both alerts appeared.

  16. #16
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    parent refresh

    Whew, that's good. How about like this (1 alert expected)
    HTML Code:
    <script language="javascript" type="text/javascript">
    <!--
    function reloadOpener(){
    //	alert("in reloadOpener");
    	setTimeout("doItNow()",2000);
    //	doItNow();
    	return;
    }
    function doItNow(){
    	alert("in doItNow");
    //	window.opener.location.reload();
    //	parent.refresh();
    	return;
    }
    //-->
    </script>

  17. #17
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No alert.

  18. #18
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I change the input type from submit to button, it works. However my form no longer submits.

  19. #19
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So I tried this:

    HTML Code:
    		<script language="javascript" type="text/javascript">
    		<!--
    		function sendForm(){
    			document.forms[0].submit();
    			reloadOpener();
    		}
    		function reloadOpener(){
    			setTimeout("doItNow()",2000);
    			return;
    		}
    		function doItNow(){
    			window.opener.location.reload();
    			return;
    		}
    		//-->
    		</script>
    With
    HTML Code:
    <input type="button" name="submit" value="Save Changes" onClick="sendForm();" />
    But it still doesn't submit.

    If I put
    Code JavaScript:
    alert(document.forms[0].name);
    in the sendForm function, it gives me the form name, but for some reason the submit() method (or rather the way I am using it) doesn't work.

  20. #20
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    form submit

    Ah, that explains things. I was scratching my head wondering why setTimeout might not be working. If you want to run code onsubmit, You could use a button and have the script submit the form.

    Maybe something like
    HTML Code:
    <input type="submit" id="submit_button"
    name="submit_button" value="Submit" class="input"
    onclick="reloadOpener(); return false;" />
    with
    HTML Code:
    var the_form = getElementById("submit_button");
    the_form.submit();
    in the function?

  21. #21
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    I was scratching my head
    I'm really sorry about that. As soon as I saw it I said to myself, "Mittineague is going to shout at his monitor!"

    Unfortunately your idea for running the code on submit doesn't work though. It brings us back to the top. Form submits, but no reload of the parent.

    I'll see you tomorrow - it's way past bedtime where I am. Thanks for sticking with me despite my lack of basic understanding of this blasted language!

  22. #22
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    submit and refresh

    I was thinking about it and realized
    HTML Code:
    var the_form = getElementById("submit_button");
    the_form.submit();
    in the child window won't work as the form is in the parent page. Maybe
    HTML Code:
    parent.getElementById("submit_button");
    or
    HTML Code:
    parent.document.getElementById("submit_button")
    ;
    ?? I don't know what the syntax would be. But I've also been wondering how to do the 2 things - both have the parent page submit the form and refresh.
    If the parent page submits to itself, it will refresh. If it goes to another page, maybe you should use parent.location.href = "the form page url here", after the script submits it?

  23. #23
    SitePoint Evangelist
    Join Date
    Nov 2007
    Posts
    472
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Try this

    <script language="javascript">
    <!--
    function reloadOpener(){
    setTimeout('doItNow()',5000);
    }
    function doItNow(){
    window.opener.location.reload();
    }
    //-->
    </script>

  24. #24
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works the same as the first thing I tried. If I use a submit, the form submits but the opener page does not reload unless I remove the setTimeout.

    If I use a button, the setTimeout works, but the form doesn't submit.

  25. #25
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    confused

    The form is not in the opener page? Please outline the desired "use flow" as best as you can, eg.
    1. filename.html opens pop-up.html upon form submit
    2. popup.html does whatever
    etc.


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
  •