Are there any security concerns to be aware of when using JavaScript to open a new window in PHP?

When using JavaScript to open a new window in PHP, one security concern to be aware of is the possibility of cross-site scripting (XSS) attacks. To mitigate this risk, make sure to sanitize any user input before using it in the JavaScript code to prevent malicious scripts from being executed.

<?php
// Sanitize user input before using it in JavaScript
$userInput = htmlspecialchars($_GET['input']);

// Output sanitized user input in JavaScript code to open a new window
echo "<script>
        var userInput = '" . $userInput . "';
        window.open(userInput, '_blank');
      </script>";
?>