javascript - how to redirect in jquery fancybox pop up to next page...in jquery -
i m using jquery fancy box popup window....for pop up.... when submit ...my form redirect in same window.....in popup.. want redirect page open window....not in same popup...
i used target blank ..but work every..time on click...i need redirect when got login done.... m creating project in codeigniter.....
my controller....
public function login() { if ( $this->input->post('action') ) { $this->form_validation->set_rules('user_name', 'username','required|valid_email'); $this->form_validation->set_rules('password', 'password', 'required|'); if ($this->form_validation->run() == true) { $username = $this->input->post('user_name'); $password = $this->input->post('password'); $rember = ($this->input->post('remember')!="") ? true : false; if( $this->input->post('remember')=="y" ) { set_cookie('username',$this->input->post('user_name'), time()+60*60*24*30 ); set_cookie('pwd',$this->input->post('password'), time()+60*60*24*30 ); } else { delete_cookie('username'); delete_cookie('pwd'); } $this->auth->verify_user($username,$password); if( $this->auth->is_user_logged_in() ) { if( $this->session->userdata('ref')!="" ) { redirect($this->session->userdata('ref'),''); } else { redirect('members/myaccount','refresh'); } } else { $this->session->unset_userdata(array("ref"=>'0')); $this->session->set_userdata(array('msg_type'=>'error')); $this->session->set_flashdata('error',$this->config->item('login_invalid')); redirect('users/login', ''); } } else { $data['heading_title'] = "login"; $this->load->view('users_login',$data); } } else { $data['heading_title'] = "login"; $this->load->view('users_login',$data); } }
class="lang-js prettyprint-override">$(window).load(function (e) { $("#back-top").hide(); $(function () { $(window).scroll(function () { if ($(this).scrolltop() > 100) { $('#back-top').fadein(); } else { $('#back-top').fadeout(); } }) }); $(".login").fancybox({ 'width': 367, 'height': 600, 'autoscale': false, 'type': 'iframe' }); $(".fotget").fancybox({ 'width': 425, 'height': 286, 'autoscale': false, 'type': 'iframe' }); $(".profile").fancybox({ 'width': 700, 'height': 505, 'autoscale': false, 'type': 'iframe' }); $(".details").fancybox({ 'width': 400, 'height': 200, 'autoscale': false, 'type': 'iframe' }); $(".enquiry").fancybox({ 'width': 359, 'height': 450, 'autoscale': false, 'type': 'iframe' }); $(".contact").fancybox({ 'width': 317, 'height': 353, 'autoscale': false, 'type': 'iframe' }); $(".map").fancybox({ 'width': 425, 'height': 355, 'autoscale': false, 'type': 'iframe' }); });
the reason happening because popup content iframed... send message parent window redirect in main browser window, google on iframe communication it's parent window should info need this, hinges on having command of page beingness iframed!
example:...where ever redirects are...replace with...
echo "<script type=\"text/javascript\">window.top.postmessage('logged_in', '*');</script>"; exit; //make sure here, stop php execution!!
then in parent window (the 1 intitializing fancyboxes...)
window.onmesage = function(e){ if(e.data == 'logged_in'){ window.location.href = 'http://pathtopage'; } }
note: 'logged_in' json string
'{ "action":"something","redirect":"http://url" }'
just utilize
json.parse(e.data);
in listener extract json object
edit: crap... misunderstood question... don't see element using submit form... e.preventdefault(); on element before letting redirect anywhere....so illustration using anchor tag...
$('a.form-submit').on('click',function(e){ e.preventdefault(); var redir = $(this).attr('href'); var formdata = $('#theform').serialize(); $.post('http://formhandler/route',formdata,function(){ //open new window... window.open(redir); //or send info parent window... window.top.postmessage(redir,'*'); }); });
javascript jquery ajax fancybox-2
No comments:
Post a Comment