简体   繁体   中英

creating new iframe after closing old one

I have an Iframe with fields which sent data to php file through ajax. If it was successful I close (it is working) iframe and create new one with another information (doen't work). 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

$.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 (); 
            $(body).html(argument[0]);
            //windows.top.frame_activation();
            frame_activation(); // does't work

        }
    });

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;
    }

You can change src of iframe to change a page display.

This is sample using Jquery :

$(document).ready(function () {
     $("#btnMenu1").click(function () {
         $("#myIframe").attr("src", "example.aspx");
     });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM