简体   繁体   中英

javascript or jquery code to obtain entire text content of web page within an iframe (including/excluding links on that page)

I know how to obtain the content of div within an iframe using jquery--

iframe content:

    <div id="myContent"></div>

jQuery:

 $("#myiframe").find("#myContent")

What I want to do is, obtain the entire text content of an iframe, both with the text of all links within that iframe, as well as text content excluding the link texts within that iframe.

I want to do this ideally using jquery, but pure js or jquery+ js is also fine with me.

You can use .contents()

<iframe src="your_url.com" id='myiframe'></iframe>

To get the whole content from iframe

$("#frameDemo").contents()

To get the data from specific element.

$("#myiframe").contents().find("#myContent")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM