How to get a page's title which in iframe?
first I have a simple iframe
<iframe src="http://www.google.com"></iframe>
I also have a button to alert the google's title
<input type="button" value="gettitle" />
then I want use jquery to get the iframe inner html's title
开发者_Go百科 $("input ").click(function () {
alert($('iframe').contents().find("title").text());
});
But it doesn't work,what's wrong with this code?How can I get the title correctly?
Here the online case
Thank you
Same origin policy will prevent you from doing that if the page in your <iframe>
element doesn't come from the same domain as your main page. Since your example uses www.google.com
, it won't work.
That said, your code is correct and should work as expected when the two pages come from the same domain.
see http://jsfiddle.net/TAtQT/7/
精彩评论