链接上的Javascript window.open在PHP中不起作用

时间:2013-10-20 20:31:26

标签: javascript php html

我的网页顶部有以下脚本,根据我传递的URL参数打开一个弹出窗口...

<Script Language="JavaScript">
function showDetails(source) {
    window.open(source,"","scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no");
}
</Script>

我有以下PHP代码调用函数来打开窗口并传递url ...

$QueryResult = @$this->DBConnect->query($SQLString);

            if ($QueryResult !== FALSE) {
                if ($QueryResult->num_rows > 0) {       
                    while (($Row = $QueryResult->fetch_assoc())
                                    !== NULL) {
                        echo "<br /><a href='javascript:showDetails(http://server/~user/PHP/EventDetails.php?PHPSESSID=".session_id()."&EventID=".$Row['EventID'].")'>".
                                htmlentities($Row['Title'])."</a>";
                    }
                }
                echo "</td>";

                if ((($FirstDOW + $i) % 7) == 0) {
                    echo "</tr>";
                }
            }

当我将鼠标悬停在网页上的链接上时,传递给该函数的网址看起来很好,我在浏览器底部看到类似这样的内容,但是,当我点击链接时它什么也没做......

javascript:showDetails(http://server/~user/PHP/EventDetails.php?PHPSESSID=Hij3234Abdc732hlae&EventID=2)

2 个答案:

答案 0 :(得分:3)

您通常将字符串放在引号中,例如

echo "<br /><a href='javascript:showDetails(\"http://server/~user/PHP/EventDetails.php?PHPSESSID="
    .session_id()."&EventID=".$Row['EventID']."\")'>".
                            htmlentities($Row['Title'])."</a>";

答案 1 :(得分:2)

语法错误。

echo "<br /><a href='javascript:showDetails(\"http://server/~user/PHP/EventDetails.php?PHPSESSID=".session_id()."&EventID=".$Row['EventID']."\")'>".htmlentities($Row['Title'])."</a>";