user3668051
user3668051

Reputation: 77

javascript popwin not working inside php

i have created a small PHP script. See bellow:

$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>";    
}

but my popwin isn't working and i wonder why, message "error" is being printed on browser page, but the popup window doesn't appears. Can anyone help telling me what i am doing wrong? how can i get popwin?

EDIT

I made a little changes in syntax,here is my full code for that page:

 $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>";    
            }

Upvotes: 1

Views: 1158

Answers (2)

Antony
Antony

Reputation: 171

Try this,

<?php

 $x=5;
    if ($x >= 8 ) {
       echo "x is ".$x;
    } else {
?>
<script>
                        function popWin(url)
                        {
                            alert(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='http://www.google.com'; //with http://
                echo "<script type='text/javascript'>               
        popWin('$errorWindow'); //with single quotes
     </script>";    
            }

?>

Upvotes: 0

AeJey
AeJey

Reputation: 1457

This is working.

<?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>";    
            }
            ?>

This too is working

<?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>";    
            }
            ?>

Upvotes: 1

Related Questions