Accidentally closing a page without submitting your comment or with a half filled form is annoying. Recently, one of our users asked us if it was possible to show their readers a confirm navigation popup? This tiny little popup alert users and prevent them from accidentally leaving half filled and unsubmitted form. In this article, we will show you how to show confirm navigation popup for WordPress forms.
What is Confirm Navigation Popup?
Let’s suppose a user is writing a comment on your blog. They have already written quite a few lines, but they get distracted and forget to submit comment. Now if they closed their browser, then the comment will be lost.
The confirm navigation popup gives them a chance to finish their comment.
You can see this feature in action in the WordPress post editor screen. If you have unsaved changes, and you try to leave the page or close the browser, then you will see a warning popup.
Let’s see how we can add this warning feature to WordPress comments and other forms on your site.
Show Confirm Navigation popup for Unsubmitted Forms in WordPress
For this tutorial, we will be creating a custom plugin, but don’t worry you can also download the plugin at the end of this tutorial to install on your website.
Let’s get started.
First you need to create a new folder on your computer and name it
confirm-leaving. Inside the confirm-leaving folder, you need to create another folder and name it js.
Now open a plain text editor like Notepad and create a new file. Inside, simply paste the following code: