How to use jquery or pure js to take element inside iframe?

0 like 0 dislike
11 views
There is a page inside that iframe with id = "iframe-5".
There is a code and it doesn't work:
$('iframe#iframe-5').load(function(){ $(this).contents().find('h1').remove(); });


Like this too:
$('iframe#iframe-5').contents().find('h1').remove();


If you take the console.log from $('iframe#iframe-5').contents(), object has length of 1, i.e. an iframe like finds and takes his data.

But if you take the console.log from $('iframe#iframe-5').contents().find('h1'), it returns an object with length = 0. For example, like this:
Object { length: 0, prevObject: {...}, context: HTMLDocument somefakeurl.com/client/statistics, selector: "h1" }

if h1 is replaced by any other tag or selector all the same.
h1 or img all these elements is inside the frame.

What am I doing wrong?
How to take element inside iframe? Are there any other ways besides contents()?
What can block? Apache security headers is disabled.
by | 11 views

2 Answers

0 like 0 dislike
Same-origin policy is not enforced, you can only frame your domain
here works
\rhttps://jsfiddle.net/1rrmfxLh/8/
by
0 like 0 dislike
api.jquery.com/contents :
\r\r$( "#frameDemo" ).contents().find( "a" ).css( "background-color", "#BADA55" );\r
by

Related questions

0 like 0 dislike
1 answer
asked Mar 22, 2019 by Savvateev
0 like 0 dislike
2 answers
asked Jun 12, 2019 by Shimpanze
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
28,666 users