Skip to content
PHP Logo

How can JavaScript be used to open a link in a pop-up window in PHP?

To open a link in a pop-up window using JavaScript in PHP, you can use the `window.open()` method. You can create a JavaScript function that opens the link in a new pop-up window when called. To trigger this function from PHP, you can echo out a script tag that calls the JavaScript function.

php
<?php
$link = "https://www.example.com";
echo "<script>";
echo "function openPopup() {";
echo "window.open('$link', '_blank', 'width=600,height=400');";
echo "}";
echo "openPopup();";
echo "</script>";
?>