Last active
July 20, 2021 10:46
-
-
Save marklchaves/4b20466eb76bddaa5f9f5edad52a9d3d to your computer and use it in GitHub Desktop.
Show a Popup Maker popup for the first, third, fifth, and sixth+ pages only.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Set up the page counter in the browser's session storage. */ | |
(function(){ | |
let pc = parseInt(sessionStorage.getItem("page-count")); | |
if (!pc) { | |
sessionStorage.setItem("page-count", 1); | |
} else { | |
if (pc >= 5) return; // Can stop counting now. | |
sessionStorage.setItem("page-count", pc += 1); | |
} | |
})(); | |
// Make sure the function (IIFE) above runs before the following jQuery. | |
jQuery(document).ready(function ($) { | |
// Display a popup on 1st, 3rd, 5th, and 6th+ pages. | |
$("#pum-1343").on("pumBeforeOpen", function (e) { // Change #pum-1343 to your popup's HTML ID. | |
let pc = parseInt(sessionStorage.getItem("page-count")); | |
const doSomethingPages = [ | |
1, 3, 5 | |
]; | |
if (doSomethingPages.includes(pc) || (pc >= 5)) { | |
// Don't need to check for conditions, but need to check for a cookie | |
// for some reason. So, we'll just check for the default cookie for now. | |
// If the default cookie exists, don't display the popup. | |
if (PUM.getCookie('pum-1343')) { | |
console.log('[PUM] Preventing popup because of cookie.'); | |
PUM.preventOpen(1343); | |
} | |
return; | |
} | |
console.log('[PUM] Preventing popup because not on page 1, 3, or 5+.'); | |
PUM.preventOpen( 1343 ) | |
}); // Listener | |
}); // jQuery | |
// Add this jQuery code to the footer area of your pages using your theme | |
// options or a plugin like Insert Headers Footers and Code Snippets. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment