1

私のコードは次のようなものです:

<?php

if($_REQUEST['post'])
{
    $title=$_REQUEST['title'];
    $body=$_REQUEST['body'];
    echo $title.$body;
}
?>

<script type="text/javascript" src="texteditor.js">
</script>

<form action="" method="post">
       Title: <input type="text" name="title"/><br>

       <a id="bold" class="font-bold"> B </a> 
       <a id="italic" class="italic"> I </a>

       Post: <iframe id="textEditor" name="body"></iframe>

       <input type="submit" name="post" value="Post" />
</form>

texteditor.js ファイルのコードは次のとおりです。

$(document).ready(function(){
document.getElementById('textEditor').contentWindow.document.designMode="on";
document.getElementById('textEditor').contentWindow.document.close();
$("#bold").click(function(){
    if($(this).hasClass("selected")){
        $(this).removeClass("selected");
    }
    else{
        $(this).addClass("selected");
    }
    boldIt();
});

$("#italic").click(function(){
    if($(this).hasClass("selected")){
        $(this).removeClass("selected");
    }
    else{
        $(this).addClass("selected");
    }
    ItalicIt();
});


});

function boldIt(){
    var edit = document.getElementById("textEditor").contentWindow;
    edit.focus();
    edit.document.execCommand("bold", false, "");
    edit.focus();
}

function ItalicIt(){  
    var edit = document.getElementById("textEditor").contentWindow;
    edit.focus();
    edit.document.execCommand("italic", false, "");
    edit.focus();
}

function post(){
    var iframe = document.getElementById("body").contentWindow;
}

実際には、これ ( andtext editorを使用して作成されたもの)からデータを取得し、別の場所に保存したいと考えています。エディターに入力されたコンテンツ (iframe など) を取得できません。iframejavascript

これで私を助けてください。

4

1 に答える 1

1

許可されていないため、それを行うことはできません。

Javascript は、セキュリティ侵害につながるため、他のフレーム/iframe へのアクセスを許可されていません。

<div></div>代わりにインラインでエディタを実装してみてくださいiframe

于 2012-06-17T21:33:51.360 に答える