Access elements of parent window from iframe Access elements of parent window from iframe ajax ajax

Access elements of parent window from iframe


I think the problem may be that you are not finding your element because of the "#" in your call to get it:

window.parent.document.getElementById('#target'); 

You only need the # if you are using jquery. Here it should be:

window.parent.document.getElementById('target'); 


You can access elements of parent window from within an iframe by using window.parent like this:

// using jquery    window.parent.$("#element_id");

Which is the same as:

// pure javascriptwindow.parent.document.getElementById("element_id");

And if you have more than one nested iframes and you want to access the topmost iframe, then you can use window.top like this:

// using jquerywindow.top.$("#element_id");

Which is the same as:

// pure javascriptwindow.top.document.getElementById("element_id");


Have the below js inside the iframe and use ajax to submit the form.

$(function(){   $("form").submit(e){        e.preventDefault();       //Use ajax to submit the form       $.ajax({          url: this.action,          data: $(this).serialize(),          success: function(){             window.parent.$("#target").load("urlOfThePageToLoad");          });       });   });});