链接中有php变量的Javascript打开窗口

Javascript open window with php variables in link?

本文关键字:Javascript 开窗口 变量 php 链接      更新时间:2023-09-26

我需要做的是打开一个新窗口,打开一个包含php变量的链接。据我所知,我不能在javascript函数中使用php变量,所以我尝试了这个似乎不起作用的

$link="<script type='text/javascript'>window.open('http://www.fonefinder.net/findome.php?npa=$num1&nxx=$num2&thoublock=$num3&usaquerytype=Search+by+Number&cityname=
')</script>";
echo $link;

$num1、$num2和$num3都是php变量。有更好的方法吗?谢谢

删除换行符:

$link="<script type='text/javascript'>window.open('http://www.fonefinder.net/findome.php?npa=$num1&nxx=$num2&thoublock=$num3&usaquerytype=Search+by+Number&cityname=')</script>";
echo $link;

此外,您应该将变量包装在大括号中:${num1},否则它们可能会被错误地插值。

$link="<script type='text/javascript'>window.open('http://www.fonefinder.net/findome.php?npa=".$num1."&nxx=".$num2."&thoublock=".$num3."&usaquerytype=Search+by+Number&cityname=')</script>";
echo $link;