Returning variable to a close event on jquery modal dialog

Posted on 2011-10-18
Last Modified: 2012-05-12
Hi all,

I've got the close event working to reload the page upon closing:

		var $login = $('#login')
				autoOpen: false,
				title: 'Login',
				draggable: false,
				modal: true,
				resizable: false,
				width: 420,
				height: 210,
				position: ['center',100],
				close: function(event,ui){
				// Dialog closing so reload the page ONLY if successful login
					window.setTimeout('location.reload()', 0);

Open in new window

Prob is, this will reload the page even if the user clicks the 'close window' option and doesn't login which is not needed (only when successfully logged in since this is when the session variables change).

Is there a way I can pass a variable back to this close event - so to speak? Do some checking - if (blah == true) { close } else { dont } type thing?

Question by:dolythgoe
    LVL 40

    Expert Comment

    why not declare that variable globally and then check that global variable?
    LVL 81

    Expert Comment

    why do you want to put the code inside close option?

    just use the following where you're able to do the test
    if(blah == true) $('#login').close();

    Author Comment


    The code is in the close option because the user can close the dialog at anytime, they do not need to complete it. The 'X' in the top right corner.

    However, if they do complete the process in the dialog - i.e. login, then the dialog is closed automatically an reloads the page.

    Perhaps I can reload the page then close the window in the else code..not sure if that will work as I thought the reload would mess with it. I'll give it a try...
    LVL 81

    Accepted Solution

    put :
    if(blah == true) $('#login').close();

    Open in new window

    anywhere you want to allow the user to close the dialog box

    if you put it inside the close event, it mean you don't need it...


    Author Comment

    The purpose is to do the following:

    - User clicks login
    - Up pops the dialog
    - User logins
    - Sessions are registered via php ajax
    - Window closes and page reloads for the session code to pick up on the registered sessions and update a few things

    I want them to be able to unconditionally close the login at any point - they don't have to complete the login.

    The issue is the reload page is issued on the close event which means it also reloads if they don't login.

    So the issue is about reloading the page depending on how it was closed - i.e. successful login or not.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    A common challenge, or question, when working with two calendar dates is: What is the difference between the specified days? As is frequently the case, the answer is: It depends... What kind of difference do you want? Given two date obje…
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now