在Perl CGI脚本中捕获iframe返回值

时间:2012-08-26 04:51:02

标签: javascript html css perl cgi

我认为这是一个非常基本的问题。我正在尝试使用Perl CGI开发一个网页。我的表单中有一个文本编辑器(使用iframe)。代码:

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

我正在尝试使用param函数捕获内容,我在文本编辑器中使用param函数在我的Perl CGI代码中提交表单。但失败!!请帮帮我。

有与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 param()函数捕获在文本编辑器中编写的值。

1 个答案:

答案 0 :(得分:0)

客户端只会传输HTML中<input>元素内的已命名<select><textarea><form>元素的数据。要从<iframe>内的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将包含文本编辑器的内容。

相关问题