Window.Open() 错误地转义了?
我是一个相对较轻的 JavaScript 用户,所以这个小操作给我带来了一些重大的痛苦——我确信我错过了一些东西。
我想要的只是打开一个弹出窗口,将一个值(emplogin,一个名为 getEmp 的字符串变量)传递到沼泽标准 .php 页面:
<script type="text/javascript">
function getEmployeeInfo(getEmp)
{
window.open ("../Pages/Employee_Info.php?emplogin=" + getEmp + ",\"mywin\",\"menubar=0,resizable=1,scrollbars=1,width=600,height=450\"");
}
</script>
并且它可以工作......有点。通过查看生成的 $_REQUEST 对象来测试结果,结果显示页面正在以
Array
(
[emplogin] =>JohnDoe,"mywin","menubar=0,resizable=1,scrollbars=1,width=600,height=450"
)
IOW 形式接收 $emplogin,Window.Open() 的第二个和第三个参数作为 PHP 接收的 $emplogin 的一部分传递,而不是由 JavaScript 解析! (我正在使用 'echo htmlspecialchars(print_r($_REQUEST, true));')
我确信我在参数转义方面做得不对,但我无法击中右侧搜索词。感谢您的任何和所有指导!
I'm a relatively light JavaScript user, so this minor operation is giving me some major grief -- I'm sure I'm missing something.
All I want is a popup to open, passing one value -- the emplogin, a string variable called getEmp -- to a bog-standard .php page thusly:
<script type="text/javascript">
function getEmployeeInfo(getEmp)
{
window.open ("../Pages/Employee_Info.php?emplogin=" + getEmp + ",\"mywin\",\"menubar=0,resizable=1,scrollbars=1,width=600,height=450\"");
}
</script>
And it works... sort of. Testing the result by looking at the resulting $_REQUEST object shows me that the page is receiving the $emplogin as
Array
(
[emplogin] =>JohnDoe,"mywin","menubar=0,resizable=1,scrollbars=1,width=600,height=450"
)
IOW, the second and third parameters for Window.Open() are being passed along as part of the $emplogin received by PHP, instead of being parsed by JavaScript! (I'm using 'echo htmlspecialchars(print_r($_REQUEST, true));')
I'm sure there's something I'm not doing right with the escaping of the parameters but I haven't been able to hit on the right search terms. Thank you for any and all guidance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
Try this:
您将第二个和第三个参数作为 URL 字符串的一部分包含在内,因此它们都被视为一个参数。
你想要的是:
window.open("../Pages/Employee_Info.php?emplogin=" + getEmp,"mywin","menubar=0,ressized=1,scrollbars=1,width=600,height=450");
You're including your second and third parameters as part of your URL string, so it's all being treated as one single parameter.
What you want is:
window.open ("../Pages/Employee_Info.php?emplogin=" + getEmp,"mywin","menubar=0,resizable=1,scrollbars=1,width=600,height=450");
事情应该是这样的:
That is how it should be:
对您的变量进行 urlencode 并删除 open 命令中其他参数的转义
urlencode your variable and remove the escaping of your other parameters in the open command