簡體   English   中英

在ASP.NET MVC 3上使用iframe創建編輯器

[英]Using an iframe on asp.net mvc 3 to create an editor

我正在asp.net mvc 3上使用iframe創建編輯器。 這是行不通的。

這是javascript:

 $(document).ready(function () {
    document.getElementById('textEditor').contentWindow.document.designMode = "on";
    document.getElementById('textEditor').contentWindow.document.close();


    $("#save").click(function () {

    alert('ooosooooo');
    if ($(this).hasClass("selected")) {
        $(this).removeClass("selected");

    } else {
        $(this).addClass("selected");
    }

    on();

});

});


function on() {

var edit = document.getElementById("textEditor").contentWindow;
edit.focus();

//edit.document.execCommand('SaveAs', '1', 'e:\');
//edit.document.execCommand('foreColor', false, "#000000");
var ifi = document.getElementById('textEditor');
alert('ifi.innerHTML');
alert(ifi.innerHTML);

alert($("#textEditor").html());

//Trying to copy the content of text editor t hidden
//not working its always empty the textEditor
$("#hidden_field_id").val($("#textEditor").html());

edit.focus();
}

這是html:

     @using (Html.BeginForm("Save", "Home", FormMethod.Post, new { enctype = "multipart/form-data", target="textEditor"}))
       {

      @*this is the iframe*@
      <iframe id="textEditor" name="textEditor" width="100%" height="500px"></iframe>
      <input type="hidden" id="hidden_field_id" name="hidden_field_id" value="ww"/>
      <input type="submit" id="save" class="save" value="send" />             
       }

問題是,當我按發送/保存在文本編輯器上插入文本時,從iframe復制到隱藏的值始終為空“”。

請嘗試以下操作:

function on() {
    var edit = document.getElementById("textEditor").contentWindow;
    var html = $('body', edit.document).html();
    $("#hidden_field_id").val(html);
}

我這樣做是這樣的:

function on() {


    edit.focus();

    var ifi = document.getElementById('textEditor');

    $("#hidden_field_id").val(ifi.contentWindow.document.body.innerHTML);

    edit.focus();
}

感謝佩德羅

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM