---
updatedAt: 2025-12-15T10:07:02.000Z
agentTools:
  projectIndex: https://developer.onetrust.com/onetrust/llms.txt
---

# Refresh Page After User Accepts or Saves Cookie Settings

```javascript JavaScript
function getCookie(name) {
    var value = "; " + document.cookie;
    var parts = value.split("; " + name + "=");
    if (parts.length == 2) return parts.pop().split(";").shift();
}

function OptanonWrapper() { 
    
    console.log("OptanonWrapper called");
    var OABCcookieName = "OptanonAlertBoxClosed";
    var bannerAcceptBtn = document.getElementById("onetrust-accept-btn-handler");
    var pcAllowAllBtn = document.getElementById("accept-recommended-btn-handler");
    var pcSaveBtn = document.getElementsByClassName("save-preference-btn-handler onetrust-close-btn-handler")[0];
    var OABCcookie = getCookie(OABCcookieName);  
   
    // IF logic needed here because ot-banner-sdk DIV is not injected on page loads if banner is not exposed
    if (!OABCcookie && bannerAcceptBtn) {
        bannerAcceptBtn.addEventListener('click', function() {
            console.log("Allowed all via Banner");
            location.reload();
        });
    }
  
    if (pcAllowAllBtn)
        pcAllowAllBtn.addEventListener('click', function() {
            console.log("Allowed all via Preference Center");
            location.reload();
        });
  
    if(pcSaveBtn){
        pcSaveBtn.addEventListener('click', function() {
            setTimeout(()=> {
            console.log("Set custom settings via Preference Center");
            location.reload();
        }, 1000) //quick timeout so that the consent receipt can be sent and the cookie can be updated
        });
    }
}
```

# Introduction



A user would incorporate this code into their website to ensure that any interactions with cookie consent mechanisms (e.g., accepting all cookies or saving preferences) trigger an immediate page reload. This helps ensure that any content or functionality dependent on the user's cookie settings is updated promptly, providing a seamless user experience.

> 📘
> 
> For the code to function correctly, ensure the relevant button elements are present in the DOM and have the specified IDs or classes.

# Function to Retrieve Cookie Value

<!-- javascript@1-6 -->

The `getCookie` function retrieves the value of a specified cookie by its name.

# OptanonWrapper Function

<!-- javascript@7-38 -->

The `OptanonWrapper` function sets up event listeners to refresh the page when the user interacts with cookie consent buttons.

# Banner Accept Button

<!-- javascript@17-22 -->

Checks if the cookie is not set and the button exists, then adds an event listener to refresh the page on click.

# Preference Center Allow All Button

<!-- javascript@24-28 -->

Adds an event listener to refresh the page when the `accept-recommended-btn-handler` button is clicked.

# Preference Center Save Button

<!-- javascript@30-37 -->

Adds an event listener to refresh the page with a slight delay after clicking the save button to ensure preferences are saved.

# Logging and Debugging

<!-- javascript@9,19,26,33 -->

Each event listener includes `console.log` statements to provide feedback in the browser's console for debugging purposes.