如何发送变量与窗口.打开JavaScript函数

How to send variable with window.open JavaScript function

本文关键字:打开 JavaScript 函数 窗口 何发送 变量      更新时间:2023-09-26

我想发送一个变量到一个新的窗口,当使用window.open函数。下面是我的代码:

<html>
<head>`enter code here`
<script>
function myFunction(){
    window.open('test4.php?id=5', '_blank', 'toolbar=0,location=0,menubar=0');
}
</script>
</head>
<body>
<?php
    $id=5;
?>
<button onclick="myFunction()">Click Here</button>
</body>
</html>

PHP变量$id=5是我试图传递到下一页。

<html>
<head>`enter code here`
 <script>
 function myFunction(value){
// getting value you want to pass
 window.open('test4.php?id=' + value, '_blank', 'toolbar=0,location=0,menubar=0');
}
 </script>
 </head>
 <body>
 <?php
 $id=6;
?>
//you can add php value in any html like that.
 <button onclick="myFunction(<?php echo $id;?>)">Click Here</button>
 </body>
 </html>

最后说明:在提出这样的问题之前,你应该先去看看这些主题的教程。