11548 sujets

JavaScript, DOM et API Web HTML5

Bonjour,

J'ai un code pour une popunder qui fonctionne très bien sur tous les navigateurs mais je n'arrive pas à y insérer le fait que la popunder doit s'ouvrir 1 fois par jour pour chaque internaute. (sinon, c'est vraiment trop intrusif!)
Je sais que je dois gérer çà avec les cookies mais je n'arrive pas à coupler mon code ci-dessous avec tous les codes de cookie que je trouve.
Pourriez-vous m'éclairer svp ?
Ci-dessous en premier le code du fichier JS , puis le script mis dans ma page d'accueil

Merci beaucoup !

Contenu du fichier popunder.js :

var BubpuShown = false;
var BubPopWidth = 1024;
var BubPopHeight = 768;
var BubPopFocus = 0;
var Bub_Top = null;

function BubGetWindowHeight() {
var myHeight = 0;
if( typeof( Bub_Top.window.innerHeight ) == 'number' ) { myHeight = Bub_Top.window.innerHeight; } else if( Bub_Top.document.documentElement && Bub_Top.document.documentElement.clientHeight )
                { myHeight = Bub_Top.document.documentElement.clientHeight; } else if( Bub_Top.document.body && Bub_Top.document.body.clientHeight ) { myHeight = Bub_Top.document.body.clientHeight; } return myHeight; }

function BubGetWindowWidth() {
var myWidth = 0;
if( typeof( Bub_Top.window.innerWidth ) == 'number' ) { myWidth = Bub_Top.window.innerWidth; } else if( Bub_Top.document.documentElement && Bub_Top.document.documentElement.clientWidth ) { myWidth = Bub_Top.document.documentElement.clientWidth; } else if( Bub_Top.document.body && Bub_Top.document.body.clientWidth ) { myWidth = Bub_Top.document.body.clientWidth; } return myWidth; }

function BubGetWindowTop() {
return (Bub_Top.window.screenTop != undefined) ? Bub_Top.window.screenTop : Bub_Top.window.screenY; }

function BubGetWindowLeft() {
return (Bub_Top.window.screenLeft != undefined) ? Bub_Top.window.screenLeft : Bub_Top.window.screenX; }


function BubdoOpen(url)
{
var popURL = "about:blank"
var popID = "ad_" + Math.floor(89999999*Math.random()+10000000);
var pxLeft = 0; var pxTop = 0;
pxLeft = (BubGetWindowLeft() + (BubGetWindowWidth() / 2) - (BubPopWidth / 2)); pxTop = (BubGetWindowTop() + (BubGetWindowHeight() / 2) - (BubPopHeight / 2)); if ( BubpuShown == true ) return true; var PopWin=Bub_Top.window.open(popURL,popID,'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,top=' + pxTop + ',left=' + pxLeft + ',width=' + BubPopWidth + ',height=' + BubPopHeight);

if (PopWin)
{
BubpuShown = true;

if (BubPopFocus == 0)
{
PopWin.blur();
if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1) { Bub_Top.window.blur(); Bub_Top.window.focus(); } }

PopWin.Init = function(e) {

with (e) {
Params = e.Params;
Main = function(){
if (typeof window.mozPaintCount != "undefined") { var x = window.open("about:blank"); x.close(); } else if (navigator.userAgent.toLowerCase().indexOf("chrome/2") > -1) { var x = window.open("about:blank"); x.close(); }


var popURL = Params.PopURL;
try { opener.window.focus();  }
catch (err) { }
window.location = popURL;
window.blur();
}

Main();
}
};

PopWin.Params = { PopURL: url }
PopWin.Init(PopWin);
}

window.BubPopped=true;
return PopWin;
}


function BubinitPu()
{
Bub_Top = self;
if (top != self)
{
try { if (top.document.location.toString()) Bub_Top = top; }
catch(err) { }
}

if ( document.attachEvent ) { document.attachEvent( 'onclick', BubcheckTarget ); } else if ( document.addEventListener ) { document.addEventListener( 'click', BubcheckTarget, false ); } }

function BubcheckTarget(e)
{
if (window.BubPopped) return;

var e = e || window.event;
var win = BubdoOpen(spc_url);
}

if (!window.BubPopped)
                BubinitPu();



Code mis dans la page d'accueil :
<script type="text/javascript">
        spc_url = 'http://www.google.fr';
        spc_name = 'bub';
        spc_poptype = 'siteunder';
        spc_fullscreen = true;
        spc_width = 1024;
        spc_height = 768;
        if (!window.BubPopped)
                        document.write('<scr'+'ipt  src=js/pop-under.js></scr'+'ipt>');
</script>
Bonjour loupiloop,

Pour gérer les cookies, je te conseil d'utiliser une bibliothèque tiers qui va gérer les problèmes de compatibilité entre les navigateurs.

En utilisant le plugin suivant :
http://code.google.com/p/cookies/wiki/Documentation

Ton code pourrait ressembler à :

<header>
  ...
  <script type="text/javascript" src="js/jaaulde.cookies.js"></script>
</head>
<body>
  ...
  <script type="text/javascript">
        spc_url = 'http://www.google.fr';
        spc_name = 'bub';
        spc_poptype = 'siteunder';
        spc_fullscreen = true;
        spc_width = 1024;
        spc_height = 768;
        if ( jaaulde.utils.cookies.get('mon_site_popunder') == null && !window.BubPopped ) {
                        jaaulde.utils.cookies.set('mon_site_popunder', 1, {expires: 1}); // mon cookie disparait dans 1 jour
                        document.write('<scr'+'ipt  src=js/pop-under.js></scr'+'ipt>');
        }
  </script>
</body>


Bon code !

PS: Bien sur, il faut que tu mettes le fichier "jaaulde.cookies.js" téléchargé à l'adresse "http://cookies.googlecode.com/svn/trunk/jaaulde.cookies.js", dans ton répertoire "js" sur ton serveur.