Reputation: 6052
I'm trying to get the title of a page in an iFrame. I did look at some other questions on stackoverflow and found the following code:
var title = $("#frame").contents().find("title").html();
alert(title);
I though it should work.
But here on my jsfiddle the code doesn't seem to work. Can anyone explain to me why it wont work, and give me a suggestion of how I would get this to work. Thanks!
Upvotes: 1
Views: 1833
Reputation: 2196
(function(el, w)
{
function loadFunc(e)
{
e = e || w.event;
var f = e.target || e.srcElement, fb = f.contentDocument || f.contentWindow.document;
document.title = fb.title;
}
if (w.addEventListener)
el.addEventListener('load', loadFunc, false);
else if (w.attachEvent)
el.attachEvent('onload', loadFunc);
})
(document.getElementById('myIframe'), window);
Upvotes: 0
Reputation: 38
Cross domain, so the parent javascript will get nothing from iframe content when iframe loaded.
Upvotes: 1
Reputation: 94101
This has been asked and answered many times. You can't access the contents of another domain from your domain. It would be a security risk.
Upvotes: 0