Jquery how to get contents of iframe header value

I have an iframe and I want to get the value of the content of the header.

 <iframe> <html> <head> <style>body{color:red;}</style> <link type="text/css" rel="stylesheet" href="some link"> </head> </html> </iframe> 

I tried this script:

 var sett_wped_head = jQuery('iframe').contents().find("head").text(); alert(sett_wped_head); 

but returns body{color:red;} . my goal is to get value

 <style>body{color:red;}</style> <link type="text/css" rel="stylesheet" href="some link"> 

Is it possible?

+5
source share
1 answer

You need to use html() to get the html content inside

 var sett_wped_head = jQuery('iframe').contents().find("head").html(); // ------^------ alert(sett_wped_head); 
+5
source

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


All Articles