Window.Open() 错误地转义了?

发布于 2024-11-13 23:18:00 字数 789 浏览 2 评论 0原文

我是一个相对较轻的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

初见终念 2024-11-20 23:18:00

试试这个:

<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>

Try this:

<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>
独享拥抱 2024-11-20 23:18:00

您将第二个和第三个参数作为 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");

深白境迁sunset 2024-11-20 23:18:00

事情应该是这样的:

<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>

That is how it should be:

<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>
不再让梦枯萎 2024-11-20 23:18:00

对您的变量进行 urlencode 并删除 open 命令中其他参数的转义

urlencode your variable and remove the escaping of your other parameters in the open command

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文