私は次のコードを持っています、
$(document.getElementById('messages_message-wysiwyg-iframe').contentWindow.document).keydown(function() {
var iFrame = document.getElementById('messages_message-wysiwyg-iframe');
var iFrameBody;
if ( iFrame.contentDocument )
{ // FF
iFrameBody = iFrame.contentDocument.getElementsByTagName('body')[0];
}
else if ( iFrame.contentWindow )
{ // IE
iFrameBody = iFrame.contentWindow.document.getElementsByTagName('body')[0];
}
console.info(iFrameBody.innerHTML);
});
iframeのコンテンツを取得したが、そうでないhtmlタグをすべて削除した場合に私がやろうとしていること
b, strong, i, a, u, img
ただし、テキストを削除したくありません。たとえば、iframeに次のようなテキストがある場合、
<div class="box segment panel">
<a href="http://www.google.com>hello world</a>
click this link and go far.
<img src="http://placehold.it/100x100" alt="Placeholder"/>
</div>
返されるものは次のようになります、
<a href="http://www.google.com">hello world</a>
click this link and go far.
</a>
<img src="http://placehold.it/100x100" alt="Placeholder" />
これも可能ですか?