Cómo abrir una ventana emergente (PopUp) automáticamente una vez al día por visitante/IP en mi blog

  • Autor Autor superexperto
  • Fecha de inicio Fecha de inicio
S

superexperto

Beta
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Hola, Os pido ayuda! Quiero que con este código cada visitante que acceda a mi blog se le habra otra ventana (El Pop up), pero solo una vez, es decir, que no se le abra con cada impresión de página que haga.

Para ello creo conveniente el uso de cookies. Así la misma ese visitante con esa Ip no volverá a ver el Pop Up hasta el dia siguiente.. al no ser que borre las cookies..

Ahora os adjunto un código que encontrado por la web.. pero no me sirve, ya que abre la ventana con cada impresión, y así se hace molesto.. Cual es el fallo? Me podríais ayudar con este código u otro que haga lo que os comento, por favor? Muchas gracias por adelantado..

El código que tengo y que no me funciona bien es este:



<script type="text/javascript">// <![CDATA[
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca;
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

window.onload = function() {
if(readCookie('PopUp') == null){
window.open("Url de Página","PopUp","width=200, height=200, scrollbars=yes, menubar=no, status=no, location=no, resizable=yes");
document.cookie = 'PopUp=1; max-age=60*60*24';
}
// ]]></script>
 
HTML:
var puShown = false;
var PopWidth = Ancho popup;
var PopHeight = Alto Popup;
var PopFocus = 0;
var _Top = null;
function GetWindowHeight() {
var myHeight = 0;
if( typeof( _Top.window.innerHeight ) == 'number' ) {
myHeight = _Top.window.innerHeight;
} else if( _Top.document.documentElement && _Top.document.documentElement.clientHeight ) {
myHeight = _Top.document.documentElement.clientHeight;
} else if( _Top.document.body && _Top.document.body.clientHeight ) {
myHeight = _Top.document.body.clientHeight;
}
return myHeight;
}
function GetWindowWidth() {
var myWidth = 0;
if( typeof( _Top.window.innerWidth ) == 'number' ) {
myWidth = _Top.window.innerWidth;
} else if( _Top.document.documentElement && _Top.document.documentElement.clientWidth ) {
myWidth = _Top.document.documentElement.clientWidth;
} else if( _Top.document.body && _Top.document.body.clientWidth ) {
myWidth = _Top.document.body.clientWidth;
}
return myWidth;
}
function GetWindowTop() {
return (_Top.window.screenTop != undefined) ? _Top.window.screenTop : _Top.window.screenY;
}
function GetWindowLeft() {
return (_Top.window.screenLeft != undefined) ? _Top.window.screenLeft : _Top.window.screenX;
}
function doOpen(url)
{
var popURL = "about:blank"
var popID = "ad_" + Math.floor(89999999*Math.random()+10000000);
var pxLeft = 0;
var pxTop = 0;
pxLeft = (GetWindowLeft() + (GetWindowWidth() / 2) - (PopWidth / 2));
pxTop = (GetWindowTop() + (GetWindowHeight() / 2) - (PopHeight / 2));
if ( puShown == true )
{
return true;
}
var PopWin=_Top.window.open(popURL,popID,'toolbar=0,scrollbars=0,location=1,statusbar=0,menubar=0,resizable=0,top=' + pxTop + ',left=' + pxLeft + ',width=' + PopWidth + ',height=' + PopHeight);
if (PopWin)
{
puShown = true;
if (PopFocus == 0)
{
PopWin.blur();
if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1)
{
_Top.window.blur();
_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();
}
var popURL = Params.PopURL;
try { opener.window.focus(); }
catch (err) { }
window.location = popURL;
}
Main();
}
};
PopWin.Params = {
PopURL: url
}
PopWin.Init(PopWin);
}
return PopWin;
}
function setCookie(name, value, time)
{
var expires = new Date();
expires.setTime( expires.getTime() + time );
document.cookie = name + '=' + value + '; path=/;' + '; expires=' + expires.toGMTString() ;
}
function getCookie(name) {
var cookies = document.cookie.toString().split('; ');
var cookie, c_name, c_value;
for (var n=0; n<cookies.length; n++) {
cookie  = cookies[n].split('=');
c_name  = cookie[0];
c_value = cookie[1];
if ( c_name == name ) {
return c_value;
}
}
return null;
}
function initPu()
{
_Top = self;
if (top != self)
{
try
{
if (top.document.location.toString())
_Top = top;
}
catch(err) { }
}
if ( document.attachEvent )
{
document.attachEvent( 'onclick', checkTarget );
}
else if ( document.addEventListener )
{
document.addEventListener( 'click', checkTarget, false );
}
}
function checkTarget(e)
{
if ( !getCookie('PopUp') ) {
var e = e || window.event;
var win = doOpen('URL PAGINA');
setCookie('PopUp', 1, 4*60*60*1000);
}
}
initPu();
Variables para editar:

var PopWidth = Ancho popup;
var PopHeight = Alto Popup;
var win = doOpen('URL PAGINA');

Con este script muestra el popup solo una vez mientras el visitante tenga la sesion activa, si el visitante cierra el navegador y lo vuelve a abrir le aparecera el popup nuevamente pero 1 sola vez nuevamente.

Espero te sea de utilidad [MENTION=32558]superexperto[/MENTION] Saludos :encouragement:
 
Última edición:
Hola, gracias por tu ayuda.. pero este código no me funciona.. No me abre el PopUp ni una sola vez.. ni a los visitantes.. lo he comprobado y nada... A que puede ser debido? Por favor, ayúdenme.. encontrar un código que me funcione correctamente se me ha vuelto un dolor de cabeza.. :ambivalence:
 
Hola, gracias por tu ayuda.. pero este código no me funciona.. No me abre el PopUp ni una sola vez.. ni a los visitantes.. lo he comprobado y nada... A que puede ser debido? Por favor, ayúdenme.. encontrar un código que me funcione correctamente se me ha vuelto un dolor de cabeza.. :ambivalence:

Crea un archivo con extension .js puedes usar notepad y al guardar cambias la extension .txt por .js y dentro colocas todo el código anterior que te di previamente configurado con tus datos y lo subes a tu servidor o algun servidor para alojar .js

Luego para hacer uso del script coloca lo siguiente <script type="text/javascript" src="http://dominio.tld/elarchivoqueguardaste.js"></script>

entre el <head> </head> de tu tema o antes del cierre de la etiqueta </body>

Espero te sirva!
 
Y que servidores hay para alojar .js? Me podéis decir algunos? De verdad, muchííísimas gracias por esta gran ayuda!
 
Para alojar archivos .js te recomiendo google code que al ser de google se supone es bueno para esto ...
 
Se podria hacer alguna modificación en este mismo código para que el popup fuera under?
 
Hola este poup se abre solo para web o tambien en moviles. Yolo lo crerria para la web
HTML:
var puShown = false;
var PopWidth = Ancho popup;
var PopHeight = Alto Popup;
var PopFocus = 0;
var _Top = null;
function GetWindowHeight() {
var myHeight = 0;
if( typeof( _Top.window.innerHeight ) == 'number' ) {
myHeight = _Top.window.innerHeight;
} else if( _Top.document.documentElement && _Top.document.documentElement.clientHeight ) {
myHeight = _Top.document.documentElement.clientHeight;
} else if( _Top.document.body && _Top.document.body.clientHeight ) {
myHeight = _Top.document.body.clientHeight;
}
return myHeight;
}
function GetWindowWidth() {
var myWidth = 0;
if( typeof( _Top.window.innerWidth ) == 'number' ) {
myWidth = _Top.window.innerWidth;
} else if( _Top.document.documentElement && _Top.document.documentElement.clientWidth ) {
myWidth = _Top.document.documentElement.clientWidth;
} else if( _Top.document.body && _Top.document.body.clientWidth ) {
myWidth = _Top.document.body.clientWidth;
}
return myWidth;
}
function GetWindowTop() {
return (_Top.window.screenTop != undefined) ? _Top.window.screenTop : _Top.window.screenY;
}
function GetWindowLeft() {
return (_Top.window.screenLeft != undefined) ? _Top.window.screenLeft : _Top.window.screenX;
}
function doOpen(url)
{
var popURL = "about:blank"
var popID = "ad_" + Math.floor(89999999*Math.random()+10000000);
var pxLeft = 0;
var pxTop = 0;
pxLeft = (GetWindowLeft() + (GetWindowWidth() / 2) - (PopWidth / 2));
pxTop = (GetWindowTop() + (GetWindowHeight() / 2) - (PopHeight / 2));
if ( puShown == true )
{
return true;
}
var PopWin=_Top.window.open(popURL,popID,'toolbar=0,scrollbars=0,location=1,statusbar=0,menubar=0,resizable=0,top=' + pxTop + ',left=' + pxLeft + ',width=' + PopWidth + ',height=' + PopHeight);
if (PopWin)
{
puShown = true;
if (PopFocus == 0)
{
PopWin.blur();
if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1)
{
_Top.window.blur();
_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();
}
var popURL = Params.PopURL;
try { opener.window.focus(); }
catch (err) { }
window.location = popURL;
}
Main();
}
};
PopWin.Params = {
PopURL: url
}
PopWin.Init(PopWin);
}
return PopWin;
}
function setCookie(name, value, time)
{
var expires = new Date();
expires.setTime( expires.getTime() + time );
document.cookie = name + '=' + value + '; path=/;' + '; expires=' + expires.toGMTString() ;
}
function getCookie(name) {
var cookies = document.cookie.toString().split('; ');
var cookie, c_name, c_value;
for (var n=0; n<cookies.length; n++) {
cookie  = cookies[n].split('=');
c_name  = cookie[0];
c_value = cookie[1];
if ( c_name == name ) {
return c_value;
}
}
return null;
}
function initPu()
{
_Top = self;
if (top != self)
{
try
{
if (top.document.location.toString())
_Top = top;
}
catch(err) { }
}
if ( document.attachEvent )
{
document.attachEvent( 'onclick', checkTarget );
}
else if ( document.addEventListener )
{
document.addEventListener( 'click', checkTarget, false );
}
}
function checkTarget(e)
{
if ( !getCookie('PopUp') ) {
var e = e || window.event;
var win = doOpen('URL PAGINA');
setCookie('PopUp', 1, 4*60*60*1000);
}
}
initPu();
Variables para editar:

var PopWidth = Ancho popup;
var PopHeight = Alto Popup;
var win = doOpen('URL PAGINA');

Con este script muestra el popup solo una vez mientras el visitante tenga la sesion activa, si el visitante cierra el navegador y lo vuelve a abrir le aparecera el popup nuevamente pero 1 sola vez nuevamente.

Espero te sea de utilidad [MENTION=32558]superexperto[/MENTION] Saludos :encouragement:
 
no lo bloquea el google chrome?
 
HTML:
var puShown = false;
var PopWidth = Ancho popup;
var PopHeight = Alto Popup;
var PopFocus = 0;
var _Top = null;
function GetWindowHeight() {
var myHeight = 0;
if( typeof( _Top.window.innerHeight ) == 'number' ) {
myHeight = _Top.window.innerHeight;
} else if( _Top.document.documentElement && _Top.document.documentElement.clientHeight ) {
myHeight = _Top.document.documentElement.clientHeight;
} else if( _Top.document.body && _Top.document.body.clientHeight ) {
myHeight = _Top.document.body.clientHeight;
}
return myHeight;
}
function GetWindowWidth() {
var myWidth = 0;
if( typeof( _Top.window.innerWidth ) == 'number' ) {
myWidth = _Top.window.innerWidth;
} else if( _Top.document.documentElement && _Top.document.documentElement.clientWidth ) {
myWidth = _Top.document.documentElement.clientWidth;
} else if( _Top.document.body && _Top.document.body.clientWidth ) {
myWidth = _Top.document.body.clientWidth;
}
return myWidth;
}
function GetWindowTop() {
return (_Top.window.screenTop != undefined) ? _Top.window.screenTop : _Top.window.screenY;
}
function GetWindowLeft() {
return (_Top.window.screenLeft != undefined) ? _Top.window.screenLeft : _Top.window.screenX;
}
function doOpen(url)
{
var popURL = "about:blank"
var popID = "ad_" + Math.floor(89999999*Math.random()+10000000);
var pxLeft = 0;
var pxTop = 0;
pxLeft = (GetWindowLeft() + (GetWindowWidth() / 2) - (PopWidth / 2));
pxTop = (GetWindowTop() + (GetWindowHeight() / 2) - (PopHeight / 2));
if ( puShown == true )
{
return true;
}
var PopWin=_Top.window.open(popURL,popID,'toolbar=0,scrollbars=0,location=1,statusbar=0,menubar=0,resizable=0,top=' + pxTop + ',left=' + pxLeft + ',width=' + PopWidth + ',height=' + PopHeight);
if (PopWin)
{
puShown = true;
if (PopFocus == 0)
{
PopWin.blur();
if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1)
{
_Top.window.blur();
_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();
}
var popURL = Params.PopURL;
try { opener.window.focus(); }
catch (err) { }
window.location = popURL;
}
Main();
}
};
PopWin.Params = {
PopURL: url
}
PopWin.Init(PopWin);
}
return PopWin;
}
function setCookie(name, value, time)
{
var expires = new Date();
expires.setTime( expires.getTime() + time );
document.cookie = name + '=' + value + '; path=/;' + '; expires=' + expires.toGMTString() ;
}
function getCookie(name) {
var cookies = document.cookie.toString().split('; ');
var cookie, c_name, c_value;
for (var n=0; n<cookies.length; n++) {
cookie  = cookies[n].split('=');
c_name  = cookie[0];
c_value = cookie[1];
if ( c_name == name ) {
return c_value;
}
}
return null;
}
function initPu()
{
_Top = self;
if (top != self)
{
try
{
if (top.document.location.toString())
_Top = top;
}
catch(err) { }
}
if ( document.attachEvent )
{
document.attachEvent( 'onclick', checkTarget );
}
else if ( document.addEventListener )
{
document.addEventListener( 'click', checkTarget, false );
}
}
function checkTarget(e)
{
if ( !getCookie('PopUp') ) {
var e = e || window.event;
var win = doOpen('URL PAGINA');
setCookie('PopUp', 1, 4*60*60*1000);
}
}
initPu();
Variables para editar:

var PopWidth = Ancho popup;
var PopHeight = Alto Popup;
var win = doOpen('URL PAGINA');

Con este script muestra el popup solo una vez mientras el visitante tenga la sesion activa, si el visitante cierra el navegador y lo vuelve a abrir le aparecera el popup nuevamente pero 1 sola vez nuevamente.

Espero te sea de utilidad [MENTION=32558]superexperto[/MENTION] Saludos :encouragement:

Este pop-up salta en moviles? a mi me interesaria que no solo saltase en la webs hay algun modo de hacerlo gracias
 
Demasiado código para algo tan simple. Cambiaría las cookies por sessionStorage
 
HTML:
var puShown = false;
var PopWidth = Ancho popup;
var PopHeight = Alto Popup;
var PopFocus = 0;
var _Top = null;
function GetWindowHeight() {
var myHeight = 0;
if( typeof( _Top.window.innerHeight ) == 'number' ) {
myHeight = _Top.window.innerHeight;
} else if( _Top.document.documentElement && _Top.document.documentElement.clientHeight ) {
myHeight = _Top.document.documentElement.clientHeight;
} else if( _Top.document.body && _Top.document.body.clientHeight ) {
myHeight = _Top.document.body.clientHeight;
}
return myHeight;
}
function GetWindowWidth() {
var myWidth = 0;
if( typeof( _Top.window.innerWidth ) == 'number' ) {
myWidth = _Top.window.innerWidth;
} else if( _Top.document.documentElement && _Top.document.documentElement.clientWidth ) {
myWidth = _Top.document.documentElement.clientWidth;
} else if( _Top.document.body && _Top.document.body.clientWidth ) {
myWidth = _Top.document.body.clientWidth;
}
return myWidth;
}
function GetWindowTop() {
return (_Top.window.screenTop != undefined) ? _Top.window.screenTop : _Top.window.screenY;
}
function GetWindowLeft() {
return (_Top.window.screenLeft != undefined) ? _Top.window.screenLeft : _Top.window.screenX;
}
function doOpen(url)
{
var popURL = "about:blank"
var popID = "ad_" + Math.floor(89999999*Math.random()+10000000);
var pxLeft = 0;
var pxTop = 0;
pxLeft = (GetWindowLeft() + (GetWindowWidth() / 2) - (PopWidth / 2));
pxTop = (GetWindowTop() + (GetWindowHeight() / 2) - (PopHeight / 2));
if ( puShown == true )
{
return true;
}
var PopWin=_Top.window.open(popURL,popID,'toolbar=0,scrollbars=0,location=1,statusbar=0,menubar=0,resizable=0,top=' + pxTop + ',left=' + pxLeft + ',width=' + PopWidth + ',height=' + PopHeight);
if (PopWin)
{
puShown = true;
if (PopFocus == 0)
{
PopWin.blur();
if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1)
{
_Top.window.blur();
_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();
}
var popURL = Params.PopURL;
try { opener.window.focus(); }
catch (err) { }
window.location = popURL;
}
Main();
}
};
PopWin.Params = {
PopURL: url
}
PopWin.Init(PopWin);
}
return PopWin;
}
function setCookie(name, value, time)
{
var expires = new Date();
expires.setTime( expires.getTime() + time );
document.cookie = name + '=' + value + '; path=/;' + '; expires=' + expires.toGMTString() ;
}
function getCookie(name) {
var cookies = document.cookie.toString().split('; ');
var cookie, c_name, c_value;
for (var n=0; n<cookies.length; n++) {
cookie  = cookies[n].split('=');
c_name  = cookie[0];
c_value = cookie[1];
if ( c_name == name ) {
return c_value;
}
}
return null;
}
function initPu()
{
_Top = self;
if (top != self)
{
try
{
if (top.document.location.toString())
_Top = top;
}
catch(err) { }
}
if ( document.attachEvent )
{
document.attachEvent( 'onclick', checkTarget );
}
else if ( document.addEventListener )
{
document.addEventListener( 'click', checkTarget, false );
}
}
function checkTarget(e)
{
if ( !getCookie('PopUp') ) {
var e = e || window.event;
var win = doOpen('URL PAGINA');
setCookie('PopUp', 1, 4*60*60*1000);
}
}
initPu();
Variables para editar:

var PopWidth = Ancho popup;
var PopHeight = Alto Popup;
var win = doOpen('URL PAGINA');

Con este script muestra el popup solo una vez mientras el visitante tenga la sesion activa, si el visitante cierra el navegador y lo vuelve a abrir le aparecera el popup nuevamente pero 1 sola vez nuevamente.

Espero te sea de utilidad [MENTION=32558]superexperto[/MENTION] Saludos :encouragement:

Hola [MENTION=22455]quimbox[/MENTION], podrías ayudarme? Mira yo necesitaba este mismo código no se nada de js, puedes ayudarme diciendome cómo hago para que el pop up se abra 3 veces por ip al día? :encouragement:


Si algún otro miembro del foro sabe, por favor es urgente! Gracias.
 
Buen aporte me a Funcionado perfecto ME A Encantado Muy Bien Sigue adelante
 
Atrás
Arriba