2013-03-04 138 views
0

我有一个存储文件路径的变量。我正在使用弹出窗口来显示该图像。我使用下面的脚本将php变量传递给javascript

function newPopup(url) { 
    popupWindow = window.open(
     url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=yes') 

使用它作为

​​

当我给上述未存储在变量名,脚本工作正常。但是当我尝试给变量$ end_file时,它不起作用。我曾尝试以下组合

echo '<td width="150"><a href="JavaScript:newPopup(\''.'$end_file'.'\');">ScreenShot</a></td>'; 
echo '<td width="150"><a href="JavaScript:newPopup(\'{$end_file}\');">ScreenShot</a></td>'; 

但没有一个似乎工作

+0

您使用'smarty'? – 2013-03-04 07:32:44

回答

0

在你的第一个例子删除周围'$end_file'引号,它应该工作。

echo '<td width="150"><a href="JavaScript:newPopup(\''.$end_file.'\');">ScreenShot</a></td>'; 

对于第二个例子,我认为你必须使用双引号的字符串iterpolation工作。

echo "<td width='150'><a href='JavaScript:newPopup(\"$end_file\");'>ScreenShot</a></td>'; 
0
echo '<td width="150"><a href="JavaScript:newPopup(\"'.$end_file.'\");">ScreenShot</a></td>'; 
0

您只需做到以下几点:

<?php 
$x="PHP"; 
?>  
<script>alert("Hello from <?php echo $x;?>");</script>