I also have a button to ...">

How to get page title which in iframe?

first i have a simple iframe

<iframe src="http://www.google.com"></iframe>

I also have a button to warn google name

<input type="button" value="gettitle" />

then i want to use jquery to get iframe inner html header

    $("input ").click(function () {
        alert($('iframe').contents().find("title").text());
    });

But this does not work, what is wrong with this code? How can I get the title correctly?

Here is the online option

thank

+3
source share
2 answers

The same origin rule will not allow you to do this if the page in your element <iframe>does not come from the same domain as your main page. As your example uses www.google.com, it will not work.

, , .

+5

Source: https://habr.com/ru/post/1781788/


All Articles