This is sure a popular question.. But I did not post it without reading those.. well 80% of them doesn't have a valid answer.. just the talk about same origin policy.. Well My php pages r all in the same domain..
So this is what I was getting in most of the places that had some logical answers..
$(document).ready(function() {
document.title=$("#mainFrame").contents().find("head").find('title').html();
});
my iframe's id is "mainFrame".. I want to get the title of the page that loads inside the iframe & set that title as the parent's title everytime.
So is there any efficient way to do that? this snippet doesn't work.. I tried.. it returns undefined!
You don't need jQuery for this. In your parent just do:
var iFrame = document.getElementById('mainFrame'), // Or $('#mainFrame')[0],
iFrameDoc = iFrame.contentWindow.document || iFrame.contentDocument;
document.title = iFrameDoc.title;
contentDocument
is the iframe's document.
var title = $( "#frame_id").contents( ).find( "title").html( );
$( document).find( "title").html( title);
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.