← Back to all Resources

Cookie management and user redirection on page load

Custom code
Integrations

Potential solutions

Use custom code + Webflow forms

Dependencies

  • Webflow
  • Custom JavaScript

All code shared in this doc is shared under the MIT License which is in full at the end of this document.

The customer shared this example that appears on page load:

I think we could classify this as an overlay and this and the form could be built natively inside of Webflow. 

Step one, build the overlay

Build the overlay and the form natively inside of Webflow. Hide or remove the submit button. For your three options in the select field the values assigned to them should be borrower, international, and investor.

Step two, add your custom code

Add some code to ensure the form never submits. 

Webflow.push(function () {
  $("form").submit(function () {
    return false;
  });
});

Also, add some code that runs when the select element changes. 

const selectElement = document.querySelector(".select");
const expiryDate = new Date();
expiryDate.setMonth(expiryDate.getMonth() + 6);

selectElement.onchange = function () {
  let selectedValue = this.value;
  if (selectedValue === "borrower") {
    document.getElementById("overlay").style.display = "none";
    document.cookie = "overlay=1; expires=" + expiryDate.toUTCString();
    set;
  } else if (selectedValue === "international") {
    window.location.href = "https://domain.com/target-page";
    document.cookie = "overlay=2; expires=" + expiryDate.toUTCString();
    set;
  } else if (selectedValue === "investor") {
    window.location.href = "https://www.sub.domain.com/";
    document.cookie = "overlay=3; expires=" + expiryDate.toUTCString();
    set;
  }
};

All of this code would go in the before body section inside script tags. You would need to modify this to fit your use case since this is a generic example. 

But, this code closes the overlay if they select option one which lets them continue on. You would also set a cookie in this step. The other two options would redirect to whichever location you set. 

You would also need to add some code not included here which runs on page load and checks whether the cookie is set before running all of this. That code would check for cookies and depending on the cookie route you to the right page and/or show the overlay if they've purged cache or cookies or if the cookie expires. 

You can customize all of this according to your needs.

SEO Impacts

The additional question was around the impact this would have on SEO. We would recommend talking to your SEO experts on this topic, but this article may be helpful in providing guidance: 

https://moz.com/blog/popups-seo-whiteboard-friday

The TLDR; is that it can have impacts depending on a number of factors, but it’s worth consulting your SEO experts to evaluate your specific use case. 

MIT License for all code shared in doc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Related resources

Retrieving UTM Parameters and Adding Hidden Inputs to Forms

Captures UTM parameters as hidden form inputs for campaign tracking via form submissions.
Developer
Video
Custom code
Forms
Marketing

Saving and Retrieving User Input with Local Storage

How to save and retrieve user input on a form from/to local storage and show it on a thank you page.
Developer
Video
Custom code
Forms
Marketing

Using an iframe on the page

Performance and accessibility considerations when using iframes
Developer
Article
Accessibility
Performance
Custom code
Security

Creating your own middleware

A guide to creating middleware to protect your API keys when making front-end calls in Webflow
Developer
Github
Custom code
API

Dialog element for modals and popups

Build more accessible pop up elements by using the dialog element with custom elements in Webflow
Developer
Nugget
Accessibility
Custom code

Custom code workflows

Methods for working with custom code in Webflow
Developer
Article
Custom code

Dynamic no-index tag for CMS template pages

Apply no-index tags to specific CMS items
Marketer
Video
CMS
Custom code
SEO

Migrate from the legacy Hubspot app to new Hubspot app

Steps to migrate from the legacy hubspot integration to the new Hubspot app
Marketer
Nugget
Integrations

Link to specific tab using the tabs element

Low-code solution to link to specific tab with the native Webflow tab element
Developer
Video
Custom code

Adding social share links to collection template page

Low-code method of adding social media share links to CMS pages
Developer
Video
CMS
Custom code