2013-03-04 230 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>