从JavaScript Popup传递PHP页面的值

时间:2012-02-16 07:16:56

标签: php javascript popup

我有一个用JavaScript编写的弹出按钮。当用户单击该按钮时,它会打开一个PHP弹出窗口。点击时,我想通过GET或POST方法将值传递给该PHP页面,这是我弹出按钮的代码:

<form input type="BUTTON" value="popup button" onClick="javascript:popup('actionpage.php')">
</form>

<SCRIPT LANGUAGE="JavaScript">    
function popup(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=880,height=300');");
}

</script>

这里我想在用户点击“弹出按钮”时将值传递给actionpage.php。谢谢和问候,

5 个答案:

答案 0 :(得分:1)

onClick="javascript:popup('actionpage.php?foo=bar')"

答案 1 :(得分:0)

您可以在查询字符串上传递参数,并在PHP页面中处理服务器端。

另请注意,eval()的使用是不必要的,并且通常不赞成您的FORM/INPUT标记格式错误。我相信我已经在下面的例子中对其进行了更正。

<form>
    <input type="button" value="popup button" onclick="popup('actionpage.php')" />
</form>

<script>    

function popup(URL) {

    var day = new Date();
    var id = day.getTime();

    window.open(
        URL + "?id=" + id, 
        'toolbar=0, 
         scrollbars=0,
         location=0,
         statusbar=0,
         menubar=0,
         resizable=0,
         width=880,
         height=300'
    );
}

</script>

答案 2 :(得分:0)

您可以使用以下代码发送数据:

var http = new XMLHttpRequest();
http.open("POST", 'path/to/php', true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.send(params);

答案 3 :(得分:0)

function popup(URL) {
day = new Date();
**URL=URL+"?foo=bar&foo2=bar2";**
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=880,height=300');");
}

答案 4 :(得分:0)

希望这会对你有所帮助。

<form>
<input type="BUTTON" value="popup button" onClick="javascript:popup('array.php')">
</form>

<SCRIPT LANGUAGE="JavaScript">    
function popup(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL + '?id=' + id , '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=880,height=300');");
}

</script>

在PHP页面中,只需使用$_GET['id']即可获取ID。

<?php
$id = $_GET['id'];
?>