Open a popup window on Magento home page once when user open a site

Open a popup window on Magento home page once when user open a site

August 15, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Open a popup window on Magento home page once when user open a site

Opening a Popup Window on Magento Homepage Once per User Visit

Are you looking to display a popup window once when a user visits your Magento homepage? You’re not alone—this is a common requirement for e-commerce sites aiming to engage visitors and boost newsletter subscriptions.

The Current Issue: Pop-up Appears Every Time Upon Reload

The code snippet provided attempts to open the popup only on the homepage (http://website.com/). However, as you’ve observed, the popup appears every time the page is reloaded. This happens because the PHP condition checks for the current URL each time, not considering whether the user has already seen and interacted with the popup.

A Developer’s Approach: Using Cookies to Remember User Interaction

To solve this issue, we need a way to track and remember that the user has already seen the popup, even if they reload the page or revisit the site. This is where cookies come in—they allow us to store small bits of data on the client side (the user’s browser) for future use.

First, let’s update your existing code to include a cookie that stores whether the user has dismissed the popup:

<?php $currentUrl = Mage::helper('core/url')->getCurrentUrl();
$popupDismissed = Mage::getSingleton('core/session')->getPopupDismissed();

if($currentUrl=='http://website.com/' && !$popupDismissed)
{
?>

Next, when the user clicks on the “close” button or submits the form, we will set a cookie to indicate that they have dismissed the popup:

jQuery('.window .agree').click(function (e) {
    //Cancel the link behavior
    e.preventDefault();

    Mage::getSingleton('core/session')->setPopupDismissed(1);
    jQuery('#mask').hide();
    jQuery('.window').hide();
});

jQuery('#subscribeForm').submit(function(e){
    e.preventDefault();
    Mage::getSingleton('core/session')->setPopupDismissed(1);
    // Your form submission logic here
});

Finally, when the page is loaded or refreshed, we check if this cookie exists. If it does, we skip showing the popup:

if($currentUrl=='http://website.com/' && !$popupDismissed)
{
?>
// Your existing popup HTML and JavaScript code
<?php
}
?>

This updated approach ensures that the popup is shown only once, even if the page is reloaded or refreshed. The user’s interaction (clicking “close” or submitting the form) sets a cookie to remember their preference.

Conclusion: An Effective Popup Strategy

By incorporating this cookie-based solution into your Magento homepage, you can now display a popup window that appears only once per user visit. This approach respects user preferences while still allowing you to engage visitors with important information about newsletter subscriptions or special offers.

Remember, the key is to store and respect user interactions using cookies. This not only improves the user experience but also reflects best practices for managing website interactivity in Magento.

For more advanced solutions and customizations, consider exploring our expertise at Laravel Company. We specialize in helping businesses like yours unlock the full potential of Magento for e-commerce success.

Errors CLI

Our network