2012-08-26 30 views
1

我認爲它是一個非常基本的問題。我正在嘗試使用Perl CGI開發一個網頁。我的表單中有一個文本編輯器(使用iframe)。代碼:在Perl CGI腳本中捕獲iframe返回值

<iframe id="textEditor" style="width:500px; height:170px;background-color:white"> 
</iframe> 

我試圖捕捉的內容,這是我在我的Perl CGI代碼的形式發佈的,採用PARAM功能的文本編輯器正在寫。但失敗!請幫助我。

有相關的iframe代碼:

<iframe id="textEditor" style="width:500px; height:170px;background-color:white"> 
</iframe> 
<script type="text/javascript"> 
<!-- 
textEditor.document.designMode="on"; 
textEditor.document.open(); 
textEditor.document.write(\'<head><style type="text/css">body{ font-family:arial; font-size:13px; }</style> </head>\'); 
textEditor.document.close(); 
function def() 
{ 
    document.getElementById("fonts").selectedIndex=0; 
    document.getElementById("size").selectedIndex=1; 
    document.getElementById("color").selectedIndex=0; 
} 
function fontEdit(x,y) 
{ 
    textEditor.document.execCommand(x,"",y); 
    textEditor.focus(); 
} 
--> 
</script> 

我試圖捕捉用CGI參數()函數寫在文本編輯器的值。

+1

歡迎來到StackOverflow。爲了獲得最佳效果,請展示足夠的JavaScript和Perl代碼,以瞭解如何將iframe內容傳遞到服務器以及服務器腳本如何嘗試讀取它。 – mob

回答

0

客戶端只會傳遞HTML中<form>元素中名稱爲<input>,<select><textarea>元素的數據。要從中的JavaScript編輯器傳回數據,您需要使用JavaScript來設置輸入元素的值。

this tutorial,你會希望你的HTML看起來像

<form name="myForm" action=".../my-cgi-script.cgi" method="POST"> 
    <input name="editorData" type="hidden" value=""> 
    ... other input elements ... 
    <iframe id="textEditor" ...></iframe> 
</form> 

,你會需要一些JavaScript這樣按下提交按鈕時運行。

document.myForm.editorData.value = textEditor.document.body.innerHTML; 
document.myForm.submit(); 

在服務器端,參數editorData則包含文本編輯器中的內容。

+0

非常感謝。它工作完美。 – vips