Search code examples
jqueryjspcolorbox

Changing location after getting response in colorbox


I am working on one module in which I select a company name and it popup a form for password using colorbox iframe. when I enter password and submit form I get json as response. Now I want to close popup window and redirect page to another page. My code is

    $(document).ready(function(){
        var validator = $("#passwordverify").validate({ 
            rules: {  
                password: { 
                    required: true, 
                    minlength: 5 
                } 
            }, 
            messages: {  
                password: { 
                    required: "Provide a password", 
                    rangelength: jQuery.format("Enter at least {0} characters") 
                }
            },
            submitHandler: function() { 
                $.ajax({
                    url:"varifypassword.action",
                    type:"post",
                    dataType:"json",
                    data:{partyid:$("#partyid").val(), password:$("#password").val()},
                    success:function(response){
                        if(response.response == true)
                            {
                                  parent.$.fn.colorbox.close();
                                  window.location.replace("main.jsp");
                            }
                        else
                            {
                                $("#error").html("Incorrect Password");
                            }
                        }
                    }); 
            }
        });  

It is working fine but window.location.replace is working for same iframe. It opens main.jsp in same popup. How can I load it at the place of parent page.


Solution

  • Did you try to use one of these approaches already?

    parent.$.fn.colorbox.close();
    window.opener.location.href = mySite;
    

    or

    parent.$.fn.colorbox.close();
    window.parent.location.href = mySite;