2017-08-18 07:31
浏览 107


I have an iframe and I want to put PHP content in it like in a text-area.

<textarea><?php echo $content; ?></textarea>

But it does not work for an iframe. How can I solve it?


<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>
    <!-- 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 />
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duan19911992 2017-08-18 08:12

    I tested this and it works fine:

    document.documentElement.innerHTML = '<iframe id="frame"></iframe>';
    var frame = document.getElementById('frame').contentWindow.document;;
    frame.write('<html><body>It Works!</body></html>');

    You can do this also on already rendered iframe.

    解决 无用
    打赏 举报

相关推荐 更多相似问题