How to redirect to a new window in PHP?
In PHP, you can use the window.open() method in JavaScript to redirect to a new page in a new window. Here is the specific code:
<?php
$url = "http://www.example.com"; // 跳转的URL
echo '<script>window.open("'.$url.'", "_blank");</script>';
?>
The above code will open the specified URL page in a new window.
If you want to trigger a redirection when a user clicks on a link or button, you can place the above code inside a JavaScript click event handler function, as shown below:
<?php
// 在HTML页面中的JavaScript代码部分
echo '
<script>
function openNewWindow() {
var url = "http://www.example.com"; // 跳转的URL
window.open(url, "_blank");
}
</script>';
// 在HTML页面中的链接或按钮
echo '<a href="javascript:openNewWindow();">点击跳转到新窗口</a>';
?>
The above code will trigger the openNewWindow() function when the user clicks on a link or button, allowing for a page redirection in a new window.