douzhao5656 2014-01-06 20:25
浏览 79

PHP没有在iFrame中运行

Hi I am trying to make a personal code playground... I am using Code Mirror to turn into looking like an IDE (I also plan to add features of an IDE later but...). My current code is basically..

HTML (index.html)

<html>
<head>
    <link href="main.css" rel="stylesheet" type="text/css" />
    <script src="http://codemirror.net/lib/codemirror.js"></script>
    <link href="http://codemirror.net/lib/codemirror.css" rel="stylesheet" />
    <script src="http://codemirror.net/mode/htmlmixed/htmlmixed.js"></script>
    <script src="http://codemirror.net/mode/css/css.js"></script>
    <script src="http://codemirror.net/mode/javascript/javascript.js"></script>
</head>
<body>
<div class="codewindow">
        <form id="codePush" action="codePush.php" method="POST" target="codeResults">
            <textarea id="htmlWindow"></textarea>
            <textarea id="cssWindow"></textarea>
            <textarea id="jsWindow"></textarea>
            <input type="submit" />
        </form>
        <script class="code">
            var htmlCodeMirror = CodeMirror(function(elt) {
                htmlWindow.parentNode.replaceChild(elt, htmlWindow);
                }, {value: "<!-- HTML goes here -->",
                   lineNumbers: true,
                   mode: "text"});
        </script>
        <script class="code">
            var cssCodeMirror = CodeMirror(function(elt) {
                cssWindow.parentNode.replaceChild(elt, cssWindow);
                }, {value: "/* CSS goes here. */",
                   lineNumbers: true,
                   mode: "css"});
        </script>
        <script class="code">
            var jsCodeMirror = CodeMirror(function(elt) {
                jsWindow.parentNode.replaceChild(elt, jsWindow);
                }, {value: "// JavaScript goes here.",
                   lineNumbers: true,
                   mode: "javascript"});
        </script>
    </div>
    <div class="output">
        <iframe id="codeResults" name="codeResults" target="codePush.php" width="100%" height="100%" frameBorder="0.5" scrolling="yes"></iframe>
    </div>
</body>

PHP (codePush.php)

<!DOCTYPE html>
<html>
<head>
    <style>
        <?php
        echo $_GET['cssWindow'];
        ?>
    </style>
    <script type="text/javascript">
        <?php
        echo $_GET['jsWindow'];
        ?>
    </script>
</head>
<body>
    <?php
    echo $_GET['htmlWindow'];
    ?>
</body>
</html>

I have made sure the link to the iFrame works because when adding text to the PHP file in the body section it displays when submit is pressed.

I hope I have made it clear and would appreciate any help... Just for reference I am a bit of a NOoB when it comes to PHP

  • 写回答

1条回答 默认 最新

  • douyaosi3164 2014-01-10 10:29
    关注

    I'm not entriely sure what you're trying to achieve with all the code you provided, but here's a simplified version that will fix the main issue of the code not processing in codePush.php:

    <div class="codewindow">
    <form id="codePush" action="codePush.php" method="POST" target="codeResults">
        HTML:<textarea id="htmlWindow" name="htmlWindow"></textarea>
        CSS:<textarea id="cssWindow" name="cssWindow"></textarea>
        JS:<textarea id="jsWindow" name="jsWindow"></textarea>
        <input type="submit" />
    </form>
    </div>
    <div class="output">
        <iframe id="codeResults" name="codeResults" target="codePush.php" width="100%" height="100%" frameBorder="0.5" scrolling="yes"></iframe>
    </div>
    

    CodePush.php

    <!DOCTYPE html>
    <html>
        <head>
            <style>
                <?php
                echo $_POST['cssWindow'];
                ?>
            </style>
            <script type="text/javascript">
            <?php
                echo $_POST['jsWindow'];
            ?>
            </script>
        </head>
        <body>
            <?php
            echo $_POST['htmlWindow'];
            ?>
        </body>
    </html>
    

    Note that CodePush.php uses 'POST' not 'GET' so that it is consistent with your form. You were also missing 'name' attributes on the textareas which is what is used in the post (not the ids). You might want to consider adding in some checks if the fields aren't complete to avoid errors etc.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?