从 javascript 函数打开 php 页面
我有一个 php 页面,first.php,我想通过从 javascript 函数传递一些参数来打开该页面。你能帮我一下吗,谢谢。
function() {
var tableName = "<?= $p ?>"; //obtaining the value from another php file
var checkB = checkbox_form.checkbux[counter].value;
window.open('"http://localhost/first.php?q="+checkB+"&p="+tableName', '_self');
}
但是打不开页面,请帮忙。提前致谢。
I have a php page, first.php and I want to open the page with passing some arguments from a javascript function. Could you please help me, thanks.
function() {
var tableName = "<?= $p ?>"; //obtaining the value from another php file
var checkB = checkbox_form.checkbux[counter].value;
window.open('"http://localhost/first.php?q="+checkB+"&p="+tableName', '_self');
}
But I am not able to open the page, please help. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如前面的答案所述,您可以轻松地使用
window.location
打开 PHP 页面;但是,在 URL 中使用变量时,您应该始终记住使用encodeURIComponent()
JavaScript 函数对变量进行转义:As the previous answers state, you could easily use
window.location
to open a PHP page; however, you should always remember to escape your variables when using them in a URL, using theencodeURIComponent()
JavaScript function:这比你想象的要简单。
It's simpler than you'd think.
我的理解是,您需要打开另一个带有一些动态参数的选项卡或弹出窗口。
我对此有 2 个解决方案:
1- 将一些额外的 JS 附加到锚点,用户将使用 onMouseOver() 事件进行单击,并使用计算出的 URL 提供 href。目标必须设置为“_blank”。
示例:
请注意,在此示例中“myParamValue”需要是全局的。
2- 您想在 ajax 请求后打开一个新选项卡或弹出窗口吗?就我而言,我想在服务器上生成一个新的报告 PHP 页面并希望立即打开它。以前的解决方案没有帮助。
这是我愚弄弹出窗口拦截器的解决方案:
My understanding is that you need to open another tab or popup with some dynamic parameters.
I have 2 solutions for this:
1- Attach some extra JS to the anchor user will click using the onMouseOver() event and feed the href with your computed URL. The target must be set to "_blank".
Example:
Note that in this example 'myParamValue' needs to be global.
2- You want to open a new tab or pop up after an ajax request? In my case I want generate a new report PHP page on the server and want to open it immediately. Previous solution does not help.
Here is my solution to fool the pop-up blockers:
使用
use