Skip to content
PHP Logo

How can a PHP function be created to display a link as a popup when clicked?

To display a link as a popup when clicked, you can create a PHP function that generates the necessary HTML and JavaScript code to create a popup window. This can be achieved by using the JavaScript window.open() function to open a new window when the link is clicked. The PHP function can output the HTML code with the onclick event handler that triggers the JavaScript function to open the popup window.

php
function displayPopupLink($url, $linkText) {
    echo '<a href="#" onclick="window.open(\'' . $url . '\', \'_blank\', \'width=600,height=400\'); return false;">' . $linkText . '</a>';
}

// Example usage
displayPopupLink('https://www.example.com', 'Click here for popup');