Simple Automatic Popup Window using JavaScript
Do you want to create an Automatic Popup Window using JavaScript?
OK, in this article you will learn how to create JavaScript Automatic Popup Window. Popup box is a popular element for any webpage. In many places, this type of modal box is used to show any information to the user.
Suppose you ask a user to subscribe to your website. In that case, you can use this type of Automatic Popup box. In many other cases such as login forms, newsletters, ads, etc. What is needed to create this Automatic Popup Window
✅ Basic structure by HTML
✅ Need to design by CSS
✅ JavaScript to activate the popup
Do you think this type of Automatic Popup Window JavaScript is very difficult to create
In fact, you can build it using simple code.
Create Automatic Popup Window in JavaScript
The design made in this article is made by HTML, CSS, and javascript. I have created many popup boxes before without using JavaScript. However, using JavaScript will make this task much easier. You can customize it as you popup.
See the Pen Untitled by Ground Tutorial (@groundtutorial) on CodePen.
If you want to create an Automatic Popup Window and want a step-by-step tutorial then keep reading till the end of the article. After each step here, I have shown the possible results with screenshots.
1. Make a box on the webpage
I first created a basic box using the following HTML codes. All the information can be found in this box. And it will act as a pop-up box.
Some amount of CSS has been used here to design the webpage. White color has been used in the background of the box.
Depending on the width of the box: 420px and height padding: 30px 40px. Box-shadow has been used to enhance beauty.
Here I have used display: none. As a result, this box cannot be viewed under normal circumstances. The image below is just to show what changes can be made using these codes.
2. Add a profile image in the Popup Window
Added an icon. You can use a profile image instead of this icon. Although I have used this content for design. You can remove these contents when you use them in your professional work.
3. Create a button to cancel the Popup Window
Now you need to create a cancel button. This button allows the user to hide the Automatic Popup Window HTML. You must keep this button even if you use it for your professional work. There is a cross icon on the button.
3. Headings and some basic text
Now I have added some more information here. In which I first added a heading and then added some basic paragraphs.
4. Created a simple button
Now I have created a simple button here. This button is for design only. You can remove these contents while using them in your profession. The button depends on width: 150px and height padding: 10px 0.
5. JavaScript of the Automatic Popup Window
We have designed the above. Now is the time to make it work. Some basic amounts of JavaScript have been used to make it work. Whether you know Basic JavaScript or not, you can understand.
✅ The 'load' function is used here. This means that the following codes will work when your webpage is loaded.
✅ Conditions have been added to 'setTimeout' here. And here the time is set to 2000 milliseconds.
✅ Here '.popup' has 'display = block'. As a result, we see the popup box.
As a result of using 2000, you will see the Popup Window after 2 seconds. If you want to see the Automatic Popup Window after 3 seconds, then use 3000 milliseconds.
Now the close button has been activated. Simple 'display = none' is used here. When you click on the button, it will be 'display = none' and the Automatic Popup Window will be hidden.
You may have problems copying the above codes and assembling them together. So below I have provided a download button. Using this button you can download the code to create Automatic Popup Window javascript.
First, follow the tutor above and find out how it was created. Then download the codes directly using the button below. We hope you find out from this tutorial how Automatic Popup Window is created using JavaScript.
Comments
Post a Comment
Tell me what you think ??😎