gpt4 book ai didi

javascript popwin 无法在 php 中工作

转载 作者:行者123 更新时间:2023-11-28 01:16:04 25 4
gpt4 key购买 nike

我创建了一个小型 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>";
}
?>

关于javascript popwin 无法在 php 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23824182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com