【问题标题】:Capture iframe return value in Perl CGI script在 Perl CGI 脚本中捕获 iframe 返回值
【发布时间】:2012-08-27 01:21:26
【问题描述】:

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

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

我正在尝试使用 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() 函数捕获在文本编辑器中写入的值。

【问题讨论】:

  • 欢迎来到 StackOverflow。为获得最佳效果,请展示足够多的 JavaScript 和 Perl 代码,以便了解您如何尝试将 iframe 内容传递到服务器以及服务器脚本如何尝试读取它。

标签: javascript html css perl cgi


【解决方案1】:

客户端只会传递来自 HTML 中 &lt;form&gt; 元素内的名为 &lt;input&gt;&lt;select&gt;&lt;textarea&gt; 元素的数据。要从 &lt;iframe&gt; 内的 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 将包含您的文本编辑器的内容。

【讨论】:

    猜你喜欢
    • 2011-08-02
    • 2014-12-20
    • 1970-01-01
    • 2015-05-27
    • 2023-03-26
    • 2021-06-09
    • 1970-01-01
    • 2012-01-19
    • 2012-03-10
    相关资源
    最近更新 更多