Created
March 16, 2016 13:21
-
-
Save Antoinebr/30a755a5955bc9bdf1f7 to your computer and use it in GitHub Desktop.
pop-under.js
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
| function popunder(url, width, height, name) { | |
| // On désactive le popunder sur les sites mobiles | |
| if (typeof window.DetectMobileLong == 'function' && typeof window.DetectTierTablet == 'function') { | |
| if(DetectMobileLong() || DetectTierTablet() || document.location.href.match(/test_mobile/)) | |
| return false; | |
| } | |
| // On effectue un traitement différent pour Chrome | |
| if(navigator.userAgent.match('Chrome')) { | |
| // Ouverture de la nouvelle page (Simulation d'un Shift+Clic) | |
| var link = document.createElement("a"), | |
| sEvent = document.createEvent("MouseEvents"); | |
| link.href = url; | |
| document.body.appendChild(link); | |
| sEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, true, false, 0, null); | |
| link.dispatchEvent(sEvent); | |
| link.parentNode.removeChild(link); | |
| // Retour à la page principale | |
| var link = document.createElement("a"), | |
| sEvent = document.createEvent("MouseEvents"); | |
| link.href = 'http://files.opodo.fr/tests/close.html', | |
| document.body.appendChild(link); | |
| /* Simulation d'un Ctrl+clic pour afficher de nouveau la page d'origine */ | |
| sEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null); | |
| link.dispatchEvent(sEvent); | |
| link.parentNode.removeChild(link); | |
| return true; | |
| } | |
| var props = 'width=' + width + ', height=' + height, name; | |
| if (navigator.userAgent.indexOf('opera') !== -1) { | |
| props += ', scrollbars=no, menubar=no, location=no, directories=no'; | |
| } | |
| window.open("javascript:window.focus()", "_self", ""); | |
| ghost = window.open(url, '_blank', props); | |
| try { | |
| ghost.blur(); | |
| } catch (e) {} | |
| ghost.window.open('about:blank').close(); | |
| return self.focus(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment