【问题标题】:Why <script> and <iframe> tag is not working in the source page of iframe?为什么 <script> 和 <iframe> 标签在 iframe 的源页面中不起作用?
【发布时间】:2014-07-04 06:44:42
【问题描述】:

我正在开发一个在线 HTML 编辑器。为此,我使用了一个表单元素。在表单内部,有一个 Textarea 将包含 HTML 代码和一个 Iframe 将呈现 HTML 代码。表单的目标是 iframe。

这是我在编辑器中的代码:

<form id="edfrm" method="post" action="/source.php" target="frame"> 
<textarea name="code" id="code"></textarea> 
<iframe allowtransparency="false" src="/source.php" name="frame" id="frame"></iframe> 
<button id="subbutton">Submit</button> 
</form> 

当表单提交时,Textarea 的值转到 source.php,Iframe 从 source.php 收集源代码并呈现结果。

这里是source.php:

<?php
$runCode = @$_REQUEST["code"];
print $runCode ;
?>

但是当我在 Textarea 中编写带有“script”标签或“iframe”标签的 HTML 代码并提交表单时,我的项目无法运行。错误显示“加载资源失败:服务器响应状态为 403(禁止)”。当我删除“脚本”或“iframe”标签时,它工作正常。

如果我遇到服务器问题、PHP 配置问题或其他问题,请帮助我。 SVG 也可以,但 'script' 和 'iframe' 有什么问题?

我认为,这对我和其他像我一样的人来说是一个非常严重的问题。请帮忙!

示例:我正在 textarea 中编写此代码。

<!DOCTYPE html>
<html>

<head>
</head>

<body>
<canvas id = "canvas1" width = "200" height = "100" style = "border-style:solid;  border-width:1px;">
</canvas>
<script>
var cnv = document.getElementById("canvas1");
var ctx = cnv.getContext("2d");
ctx.beginPath();
ctx.arc(100,50,40,0,2*Math.PI,true);
ctx.strokeStyle = "Green";
ctx.lineWidth = "10";
ctx.stroke();
ctx.fillStyle = "Yellow"
ctx.fill();
</script>
</body>

</html>

这不起作用并给出错误。当我删除脚本标签时,代码运行。

【问题讨论】:

  • 包含你的 iframe 的页面的 url 和你的 iframe 的 url 是什么?
  • 包含iframe的页面是editor.php
  • 服务器给浏览器一个禁止的错误。阅读服务器日志以找出触发它的原因。你可能有一个反 XSS 过滤器,它只是拒绝任何看起来可能是来自用户输入的攻击的东西。

标签: javascript php html iframe


【解决方案1】:

如果我理解正确:

  1. U 将您的内容发布到 source.php。

  2. 结果代码包含一个带有属性的 iframe

    src="source.php"

  3. 所以您的页面和 iframe 都从 source.php 获取源代码。

这会导致循环,因此您使用 403 是正常的。请将您的 iframe 的 src 属性更改为其他任何值,然后重试。

【讨论】:

  • 没有。问题不存在。仅当我在 Textarea 中添加
  • 你能发送一个你的请求中发布的数据的例子和你请求的文本结果吗?例如打印 $runCode ;
  • $runCode 的结果?
  • 表单有一个目标属性。它不会递归加载。
  • 怎么办?请帮我。 @昆汀
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-06
  • 2017-01-04
  • 2017-08-12
  • 2011-12-15
  • 1970-01-01
  • 2023-03-24
相关资源
最近更新 更多