I have a dynamic iframe created in my page and loading html content inside the iframe but using jquery, not able to access the html content inside the iframe.
Based on the results over the website found below two but not applicable in my case
- iframe is having the URL of same domain as i am using /testhtm.html in the src and loading it.
- iframe is getting loaded up because i have alerted when the iframe gets loaded up after that i fire my event
Getting an error in browser while on console trying to access the iframe:
Error: Permission denied to access property 'document'
document.getElementById('testiframe').contentWindow.document.body.inne...
Trying to access my div which is inside iframe:
$("#testFrame").contents().find("#myDiv");
iframe code:
var ifr = $('<iframe/>', {
id: 'testiframe',
name: 'genericFrame',
src: '/testhtml.html?' + serializeForm(params),
style: 'display: none',
load: function(){
alert('iframe loaded !');
}
});
$('#overlay').html(ifr); // Attaching it to overlay so that iframe loads in a lightbox
Any suggestions or tricks to actually access the div and show it?
UPDATE:
I am getting something using javascript:
var ifrBody = document.getElementById('testiframe').contentWindow;
returns me window object with content but i am unable to access it
but using jquery it throws error:
var iBody = $("#testFrame").contents().find("body");
Error: Permission denied to access property 'document'