To create a popup window when a user clicks on the "Save Post" button in PHP/JavaScript, you can use JavaScript's window.open() method. This method allows you to open a new browser window or tab with custom content. Here's how you can achieve this:

  1. HTML and PHP Code: Assuming you have a PHP script that handles the saving of the post, you can add an HTML form with a "Save Post" button that triggers the JavaScript function to open the popup window.
html
<!-- post_form.php --> <!DOCTYPE html> <html> <head> <title>Save Post</title> </head> <body> <h1>Save Post</h1> <form action="save_post.php" method="post" onsubmit="openPopup()"> <!-- Your post form fields go here --> <input type="text" name="title" placeholder="Title" required> <textarea name="content" placeholder="Content" required></textarea> <button type="submit">Save Post</button> </form> <script> function openPopup() { // Open the popup window when the form is submitted window.open('', 'popupWindow', 'width=600,height=400'); } </script> </body> </html>
  1. PHP Code (save_post.php): In the save_post.php script, you can handle the saving of the post to the database and then close the popup window using JavaScript. You can use the window.close() method to close the popup window when the post is successfully saved.
php
<?php // save_post.php // Your code to save the post to the database goes here // Close the popup window after the post is saved echo '<script>window.close();</script>'; ?>

In this example, when the user clicks the "Save Post" button, the form is submitted to the save_post.php script, which saves the post to the database. After the post is saved, the window.close() JavaScript function is executed, closing the popup window.

Keep in mind that modern browsers often block popup windows by default, so you may need to adjust browser settings or use a more user-friendly approach like displaying a modal dialog using JavaScript frameworks like jQuery UI, Bootstrap, or custom CSS/JavaScript.

Have questions or queries?
Get in Touch