2012-03-17 38 views
1

我在asp.net mvc 3上使用iframe來創建編輯器。這不起作用。在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始終爲空「」。

回答

0

嘗試以下操作:

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

我沒有這樣說:

function on() { 


    edit.focus(); 

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

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

    edit.focus(); 
} 

感謝 佩德羅

相關問題