Skip to content

Instantly share code, notes, and snippets.

@marklchaves
Last active October 20, 2024 11:55
Show Gist options
  • Save marklchaves/28ac87beeea5155c19d2502dca5ef316 to your computer and use it in GitHub Desktop.
Save marklchaves/28ac87beeea5155c19d2502dca5ef316 to your computer and use it in GitHub Desktop.
Create a popup cookie when you click a link but before navigating to that link
jQuery(document).ready(function ($) {
// Listen for the link click, then do stuff.
// Link will be something like <a class="do-something" href="https://myawesomewebsite.xyz/my-redirect-page/">Click me!</a>
$('.do-something').click(function (e) {
e.preventDefault(); // Don't redirect yet.
console.log('Creating the cookie.');
$('#popmake-160').trigger('pumSetCookie'); // Set the cookie first. Change to your cookie name.
console.log('Grabbing the link URL for the redirect.');
const redirectURL = $(this).attr('href'); // Get the redirect URL. Assumes this is a valid URL.
console.log('Redirecting to ' + redirectURL + '. Wait for it ;-) ... ');
setTimeout(function() {
window.location.href = redirectURL; // Now, you can redirect.
}, 1500); // 1.5 s delay. Change this to what you want.
});
}); // jQuery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment