[英]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]
一切似乎都还好,除非没有
[object HTMLBodyElement]
我无法获得iframe的值
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]
. 当我
console.log(content)
,我得到<body>...</body>
但是尝试将其存储到数据库中时,它说是[object HTMLBodyElement]
。
I have tried converting the iframe value to a string but not luck. 我试过将iframe值转换为字符串,但没有运气。
How can I get the value of the iframe as a string? 如何获取iframe的值作为字符串?
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? 有更好的方法吗,例如将Iframe的值移动到textarea,然后在组件类中获取textarea的值?
let content = this.richtextarea.nativeElement.contentDocument.body
is giving to you the element not the string html for this you need to use outerHTML : 给您元素而不是字符串html,您需要使用externalHTML :
this.richtextarea.nativeElement.contentDocument.body.outerHTML
this.richtextarea.nativeElement.contentDocument.body.innerHTML
I solved it by using inner HTML 我通过使用内部HTML解决了它
this.richtextarea.nativeElement.contentDocument.body.innerHTML
Hope this helps you 希望这对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.