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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Javascript Alert Box - catch click

    Hi

    I would like to catch the click of an alert box (if possible?) and reload location at this point. Currently I have reload at the end of the function which is not the desired behaviour. I don;t wish to use the Confirm() as this has a cancel button that has no relevance in this scenario. Maybe Confirm() is my only option?





    Code:
    function myFunction(url, myuser, myprocessing){
    	
        var xhr = $.ajax({
            "url": url,
            "data": { creatio: myuser, reqiu : myprocessing},
            "error": 
                    function(jqXHR, textStatus, errorThrown) {
            				alert(jqXHR.responseText);     			
                    
            },
            "success": 
                function(jqXHR, textStatus, errorThrown) {
        				alert("Success"); << ONCLICK of Alert... location.reload(); >>
        				
                        if($('#inspect-modal').data('modal').isShown == true) {
                        	$('#inspect-modal').modal('hide');
                        }
                        
                
        }
    });
        location.reload(); <<remove this>>
    }

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    If you put the location.reload() right after the alert, it will reload after the alert has been closed. alert is synchronous, i.e. the browser waits until the alert has been confirmed before continuing with the regular program flow.

  • #3
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i thought i tried this but what was happening was the alert box didnt behave correctly --used to flash up with no text and disappear-- however i'm a javascript novice so its possible i had something else wrong too.... i'll try again later...thanks

  • #4
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks! I must have had a typo the first time...

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,478
    Thanks
    0
    Thanked 635 Times in 625 Posts
    Just remember that in some browsers people are given the option to turn off JavaScript whenever an alert displays - it is intended only for debugging and should not appear in a live script.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    New Coder
    Join Date
    May 2013
    Posts
    45
    Thanks
    10
    Thanked 0 Times in 0 Posts
    I'd recommend using console.log(stuff) instead of alert(stuff) and press F12 if you're using Google Chrome.


  •  

    Tags for this Thread

    Posting Permissions

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