Results 1 to 10 of 10

Thread: Reload() function not working inside another javascript function in Firefox.

  1. #1
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Reload() function not working inside another javascript function in Firefox.

    Hai All...
    I want to refresh the page automatically ,after a function activate().
    But its not working in Firefox.But fine in IE 6.

    Here is the code:

    function activate()
    {

    var where_to= confirm("Do you realy want to activate?");
    if (where_to== true)
    {
    //some PHP code

    }
    window.document.location.reload(true);

    }
    else
    {
    return false;
    }

    return true;
    }

  2. #2
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Help needed

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    1. The code you've furnished in your posting seems to be incorrect and illogical. The way you've used the else part looks incorrect. Is this your complete JS code that makes the issues?

    2. You use a return statement in the event of a window reloading this seems to be meaningless.

    3. Provide a link of your page so that the we can have a look at it.

    4. The correct one is the following:
    Code:
    window.location.reload(true);

  4. The Following User Says Thank You to codeexploiter For This Useful Post:

    Vithya (09-16-2008)

  5. #4
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Is it correct now?
    But needs to refresh for seeing the result?
    I think error may be in this part of javascript only.
    becoz there is no other place i used to execute this function

    function activate()
    {

    var where_to= confirm("Do you realy want to activate?");
    if (where_to== true)
    {
    <?php
    //some php code
    ?>


    }

    window.location.reload(true);
    return true;

    }

  6. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    FF has always been more reluctant to reload pages than IE. There is some sort of logic involved, intended to avoid an endless loop of reloading, but it often goes overboard, erring on the side of caution. That said, the code you supplied makes it look as though the page always reloads, regardless of whether or not the PHP generated code is run. If activate() is called onload, it would make the likelihood of a loop very high.

    In any case, it can often help to have a separate function for the reloading, and to use a short timeout to call it:

    Code:
    function doit(){
    window.location.reoad(true);
    };
    Then wherever you want a reload use:

    Code:
    setTimeout('doit()', 20);
    But, as I said, your code looks as though activate always reloads the page. If that is not your intention, try it like:

    Code:
    function activate(){
    if (confirm("Do you realy want to activate?")){
    
    <?php
    //some php code
    ?>
    
    window.location.reload(true);
    }
    return true;
    };
    Finally though, since we cannot see what the PHP code is doing, we have no way of knowing for sure what the problem really is:

    Please post a link to the page on your site that contains the problematic code so we can check it out.
    Last edited by jscheuer1; 09-16-2008 at 11:21 AM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Vithya (09-16-2008)

  8. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Code:
    function activate(){
    	var where_to= confirm("Do you realy want to activate?");
    	if (where_to== true){
    		<?php
    			//some php code
    		?>
    	}
    	window.location.reload(true);
    	return true;	
    }
    In the above code snippet you need understand whatever PHP code you've mentioned within the if construct of JS will be executed at the server side before sending the page's markup and JS part to the client browser.

    According to your code snippet whether the condition is true or false it will reload the page. As I've mentioned earlier there is no point of returning a value from the above function as you are reloading the page which will completely change the current state to the page's initial state. Rest of the code now seems logical, though I don't know what will be the result that comes to the client browser after the PHP code processing.

  9. The Following User Says Thank You to codeexploiter For This Useful Post:

    Vithya (09-16-2008)

  10. #7
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Thank u for the response.
    Thanks for the suggestions .
    function activate()
    {

    var where_to= confirm("Do you realy want to activate?");
    if (where_to== true)
    {
    <?php
    //some php code update query for changing the status & mail function here
    ?>
    window.location.reload(true);
    }
    }

    activate() is called onclick .
    Changed the coding as per ur suggestion.But still its not refreshing after changing the status.needs to refresh manually.

  11. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Perhaps:

    Code:
    function doit(){
    window.location.reoad(true);
    };
    
    function activate(){
    if (confirm("Do you realy want to activate?")){
    
    <?php
    //some php code update query for changing the status & mail function here
    ?>
    
    setTimeout('doit()', 20);
    };
    };
    Please post a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  12. #9
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    i cant able to give the link..
    becoz its in local ...

    Quote Originally Posted by Vithya View Post
    Is it correct now?
    But needs to refresh for seeing the result?
    I think error may be in this part of javascript only.
    becoz there is no other place i used to execute this function

    function activate()
    {

    var where_to= confirm("Do you realy want to activate?");
    if (where_to== true)
    {
    <?php
    //some php code
    ?>


    }

    window.location.reload(true);
    return true;

    }

  13. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    i cant able to give the link..
    becoz its in local ...
    At this point then:

    1. Publish the code as it appears in 'view source' in FF before activate is run.
    2. Try each suggestion and report back.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •