我有一个iframe
,我想把PHP内容放在文本区域中。
<textarea><?php echo $content; ?></textarea>
但它对iframe
无效。我该如何解决?
代码:
<form action="php_parsers/article_parser.php" id="writearticle" name="writearticle" method="POST">
<p style="text-align: center; font-size: 22px;">Create Article</p>
<textarea name="title" id="title" type="text" maxlength="100" placeholder="Article Title"></textarea>
<div class="toolbar">
<a onclick="iBold()"><i class='fa fa-bold'></i></a>
<a onclick="iUnderline()"><i class='fa fa-underline'></i></a>
<a onclick="iItalic()"><i class='fa fa-italic'></i></a>
<a onclick="iFontSize()"><i class='fa fa-font'></i></a>
<a onclick="iForeColor()"><i class='fa fa-align-left'></i></a>
<a onclick="iHorizontalRule()"><i class='fa fa-align-center'></i></a>
<a onclick="iUnorderedList()"><i class='fa fa-list-ul'></i></a>
<a onclick="iOrderedList()"><i class='fa fa-list-ol'></i></a>
<a onclick="iLink()"><i class='fa fa-link'></i></a>
<a onclick="iUnlink()"><i class='fa fa-chain-broken'></i></a>
<a onclick="iJustLeft()"><i class='fa fa-align-left'></i></a>
<a onclick="iJustCenter()"><i class='fa fa-align-center'></i></a>
<a onclick="iJustRight()"><i class='fa fa-align-right'></i></a>
<a onclick="iImage()"><i class='fa fa-picture-o'></i></a>
</div>
<!-- Hide(but keep) normal textarea and place in the iFrame replacement for it -->
<textarea style="display:none;" name="myTextArea" id="myTextArea" cols="100" rows="14"></textarea>
<iframe name="richTextField" id="richTextField"></iframe>
<!-- End replacing normal textarea -->
<br />
<br />
<button id="article_btn" onclick="saveArticle()">Save Article</button>
<br />
<br />
<br />
</form>
答案 0 :(得分:1)
我对此进行了测试并且工作正常:
document.documentElement.innerHTML = '<iframe id="frame"></iframe>';
var frame = document.getElementById('frame').contentWindow.document;
frame.open();
frame.write('<html><body>It Works!</body></html>');
frame.close();
您也可以在已呈现的iframe上执行此操作。