Created
July 10, 2020 11:08
-
-
Save KeithNdhlovu/1d1abd0ea596205ae772836d5b618539 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Instance of Ad | |
| var banner = new Ad(params) | |
| // Set the name of the hidden property and the change event for visibility | |
| var hidden, visibilityChange; | |
| if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support | |
| hidden = "hidden"; | |
| visibilityChange = "visibilitychange"; | |
| } else if (typeof document.msHidden !== "undefined") { | |
| hidden = "msHidden"; | |
| visibilityChange = "msvisibilitychange"; | |
| } else if (typeof document.webkitHidden !== "undefined") { | |
| hidden = "webkitHidden"; | |
| visibilityChange = "webkitvisibilitychange"; | |
| } | |
| // If the page is hidden, pause tracking impressions | |
| // if the page is shown, resume tracking impressions | |
| function handleVisibilityChange() { | |
| if (document[hidden]) { | |
| banner.pause() | |
| } else { | |
| banner.resume() | |
| } | |
| } | |
| // Warn if the browser doesn't support addEventListener or the Page Visibility API | |
| if (typeof document.addEventListener === "undefined" || hidden === undefined) { | |
| console.log("This SDK requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API."); | |
| } else { | |
| // Handle page visibility change | |
| document.addEventListener(visibilityChange, handleVisibilityChange, false); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment