我正在開發一個在線HTML編輯器。爲此,我使用了一個表單元素。在表單中,有一個Textarea包含HTML代碼和一個可以呈現HTML代碼的Iframe。表單的目標是Iframe。爲什麼<script>和<iframe>標記在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,I幀從source.php收集的源代碼,並呈現結果。
這裏是source.php:
<?php
$runCode = @$_REQUEST["code"];
print $runCode ;
?>
但是,當我寫在的textarea的「腳本」標籤或「IFRAME」標記HTML代碼並提交表單,我的項目不起作用。錯誤說:「無法加載資源:服務器響應的狀態爲403(禁止)」。當我刪除'腳本'或'iframe'標籤時,它工作正常。
如果我面對服務器問題,PHP配置問題或其他問題,請幫助我。 SVG也可以,但'腳本'和'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和您的Iframe的網頁的網頁的網址? – obayhan
包含iframe的頁面是editor.php – hmc
服務器正在給瀏覽器一個禁止的錯誤。閱讀服務器日誌以找出觸發該事件的原因。你可能有一個反XSS過濾器,只是拒絕任何看起來可能是用戶輸入攻擊的東西。 – Quentin