0

I have an Iframe with formwhi fields wich sent data to php file through ajax. If it was successful I close iframe (it is working) and create new one with another information. So question is: how to close the old iframe and open another one?

so here is ajax function that works but doesn't open a new iframe the function opening a new iframe work by it self but doesn't work in ajax. Where is a problem?

$.ajax({

        type: "POST",
        url: "sign.php",
        data: {name : name,
            data: canvasData
            },
        success: function () {

           //frame_activation(); //if it will be here it will open iframe inside the old one iframe. 
            alert('done');
            close_frame (); //closing frame with form
            $(body).html(argument[0]);
            //windows.top.frame_activation();
            frame_activation(); // does't work, doesn't open a new iframe

        }
    });

So the result is - the old iframe sent information and close it, but doesn't open a new iframe.

frame activation :

function frame_activation() {   
//document.getElementById('bg_frame').style.visibility = 'visible';
reg = document.createElement('iframe');
document.body.appendChild(reg);
reg.id = 'iframe';
reg.src = 'activate.html';
reg.style.width='600px';
reg.style.height='200px';
position_frame(reg);
reg.style.border='solid 5px #d4d4d4';
alert('here');
return false;
}

function to close iframe:

function close_frame () {
    parent.document.getElementById('bg_frame').style.visibility = 'hidden';
    var el = parent.document.getElementById('iframe');
    el.style.display='none';
    parent.document.body.removeChild(el);   
    return(false);  
}

function for creating first iframe with fields

function frame_reg() {  
    document.getElementById('bg_frame').style.visibility = 'visible';
    reg = document.createElement('iframe');
    document.body.appendChild(reg);
    reg.id = 'iframe';
    reg.src = 'frame.html';
    reg.style.width='640px';
    reg.style.height='400px';
    position_frame(reg);
    reg.style.border='solid 5px #d4d4d4';
    return false;
    }
ZeroVash
  • 546
  • 4
  • 20
  • Since you close the window before you open the other window, it's going to stop right there, meaning it won't ever open up that 2nd window. You'll need to add the `fram_activation()` somewhere inside `close_frame()` or hook into [`window.onbeforeunload` / `window.onunload`](http://stackoverflow.com/a/13443562/2518525). – Darren Aug 13 '15 at 05:47
  • why you want to remove Iframe and then add,it seems that you just need to change the Iframe's `src` attribute – Sky Fang Aug 13 '15 at 06:00
  • because there are two different iframes with different functionality, plus for education - fr future use – ZeroVash Aug 13 '15 at 07:55

0 Answers0