【发布时间】: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