链接上的Javascript window.open在PHP中不起作用
问题描述:
I have the following script located at the top of my web page to open a popup window based on the URL parameter I pass it...
<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>
And I have the following PHP code that calls the function to open the window and passes the 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>";
}
}
When I hover over the link on the web page the URL passed to the function looks fine, and I see something like this at the bottom of the browser, however, when I click the link it does nothing...
javascript:showDetails(http://server/~user/PHP/EventDetails.php?PHPSESSID=Hij3234Abdc732hlae&EventID=2)
我的网页顶部有以下脚本,根据URL参数I打开弹出窗口 通过它... p>
&lt; Script Language =“JavaScript”&gt;
function showDetails(source){
window.open(source,“”,“scrollbars = 没有,菜单栏=没有,高度= 600,宽度= 800,可调整大小=是,工具栏=没有,位置=没有,状态=无“); \ N}
&LT; / SCRIPT&GT;
代码> 预 >
我有以下PHP代码调用函数打开窗口并传递url ... p>
$ QueryResult = @ $ this - &gt; DBConnect-&gt;查询($ SQLString);
if if($ QueryResult!== FALSE){
if($ QueryResult-&gt; num_rows&gt; 0){
while(($ Row = $ QueryResult-&gt; fetch_assoc())
!== NULL){
echo“&lt; br /&gt;&lt; a href ='javascript:showDetails(http:// server / ~user / PHP / EventDetails。 PHP PHPSESSID =安培?”的session_id()。 “事件ID =” $行[“事件 ID']。“)'&gt;”。
htmlentities($ Row ['Title'])。“&lt; / a&gt;”;
}
}
echo“&lt; / td&gt;”; \ n
if(($ FirstDOW + $ i)%7)== 0){
echo“&lt; / tr&gt;”;
}
}
code> pre>
当我将鼠标悬停在网页上的链接上时,传递给该函数的URL看起来很好,我在浏览器底部看到类似这样的内容,但是,当我点击链接时它什么也没做... p>
的javascript:showDetails(HTTP://server/~user/PHP/EventDetails.php PHPSESSID = Hij3234Abdc732hlae&安培;事件ID = 2)
代码> 预 >
div>
答
Syntax error.
echo "<br /><a href='javascript:showDetails(\"http://server/~user/PHP/EventDetails.php?PHPSESSID=".session_id()."&EventID=".$Row['EventID']."\")'>".htmlentities($Row['Title'])."</a>";
答
You normally put strings in quotes, like
echo "<br /><a href='javascript:showDetails(\"http://server/~user/PHP/EventDetails.php?PHPSESSID="
.session_id()."&EventID=".$Row['EventID']."\")'>".
htmlentities($Row['Title'])."</a>";