简体   繁体   中英

How to get the content of an iframe in angular5

I am trying to program a WYSIWYG for an app. Everything seems to be okay , except that I can't get the value of the iframe, without the [object HTMLBodyElement]

let content = this.richtextarea.nativeElement.contentDocument.body

When I console.log(content) , I get <body>...</body> but trying to store it to database, it says its an [object HTMLBodyElement] .

I have tried converting the iframe value to a string but not luck.

How can I get the value of the iframe as a string?

Is the any better way of doing this, for instance moving the value of the Iframe to a textarea then get the textarea value in component class?

let content = this.richtextarea.nativeElement.contentDocument.body

is giving to you the element not the string html for this you need to use outerHTML :

this.richtextarea.nativeElement.contentDocument.body.outerHT‌​ML

or innerHTML :

this.richtextarea.nativeElement.contentDocument.body.innerHT‌​ML

I solved it by using inner HTML

this.richtextarea.nativeElement.contentDocument.body.innerHT‌ML

Hope this helps you

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