我创建了一个小的PHP脚本。见下面:

$x=5;
if ($x >= 8 ) {
   echo "x is ".$x;
} else {
   echo 'error';
   $errorWindow = 'www.google.com';
   echo "<script type='text/javascript'>
        popWin('$errorWindow', 'windowname', 'width=400,height=300,scrollbars=yes');
     </script>";
}


但是我的popwin无法正常工作,我想知道为什么,浏览器页面上显示了“错误”消息,但没有出现弹出窗口。谁能告诉我我在做什么错?我如何获得popwin?

编辑

我对语法进行了一些更改,这是该页面的完整代码:

 $x=5;
    if ($x >= 8 ) {
       echo "x is ".$x;
    } else {
?><script type="text/javascript">
                        function popWin(url)
                        {
                            var thePopCode = window.open(url,'','height=800, width=1000, top=500, left=200, scrollable=yes, menubar=yes, resizable=yes');
                            if (window.focus)
                            {
                                thePopCode.focus();
                            }
                        }
                    </script>
                <?php
                $errorWindow='google.com';
                echo "<script type='text/javascript'>
        popWin($errorWindow);
     </script>";
            }

最佳答案

可以了

<?php
$x=5;
if($x >= 8 ) {
       echo "x is ".$x;
    } else {
    echo "Error";
?><script type="text/javascript">
                        function popWin(url)
                        {
                            var thePopCode = window.open(url,'','height=800, width=1000, top=500, left=200, scrollable=yes, menubar=yes, resizable=yes');

                            if (window.focus)
                            {
                                thePopCode.focus();
                            }
                        }
                    </script>
                <?php
                $errorWindow='google.com';
                echo "<script type='text/javascript'>
                popWin('google.com');
     </script>";
            }
            ?>


这也正在工作

<?php
$x=5;
if($x >= 8 ) {
       echo "x is ".$x;
    } else {
    echo "Error";
?><script type="text/javascript">
                        function popWin(url)
                        {
                            var thePopCode = window.open(url,'','height=800, width=1000, top=500, left=200, scrollable=yes, menubar=yes, resizable=yes');

                            if (window.focus)
                            {
                                thePopCode.focus();
                            }
                        }
                    </script>
                <?php
                $errorWindow='google.com';
                echo "<script type='text/javascript'>
                popWin('".$errorWindow."');
     </script>";
            }
            ?>

09-17 09:59