JQuery: get iframe content, same domain

I want to get .text() iframe, but it does not work. Iframe is in the same domain. In one click I load the page into a frame, and on the second I want to display the content in the message, but I get an empty warning.

 <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready( function() { // load simple paage to the frame $("#load").click( function(){ $("<iframe id='theframe' width='400' // single line height='400' src='http://localhost/dummy.html'/>").appendTo('body'); } ); // display the content - but I get empty alert $('#content').click( function() { var content; content = $("#theframe").text(); alert(content); }); }); </script> </head> <body> <a id='load' href="#">load</a> <a id='content' href="#">check content</a> </body> </html> 
+4
source share
1 answer

Taken from: Selecting an item in iFrame jQuery

 var iframe = $('iframe'); // or some other selector to get the iframe $('[tokenid=' + token + ']', iframe.contents()).addClass('border');` 
+6
source

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


All Articles