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

superexperto Seguir

Beta
Verificación en dos pasos desactivada
Desde
1 Nov 2012
Mensajes
70
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>
 

quimbox

1
Iota
Verificado
Verificación en dos pasos activada
Verificado por Whatsapp
¡Ha verificado su Paypal!
Verificado por Binance
Suscripción a IA
Desde
22 Mar 2012
Mensajes
2.340
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:

superexperto

Beta
Verificación en dos pasos desactivada
Desde
1 Nov 2012
Mensajes
70
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:
 

quimbox

1
Iota
Verificado
Verificación en dos pasos activada
Verificado por Whatsapp
¡Ha verificado su Paypal!
Verificado por Binance
Suscripción a IA
Desde
22 Mar 2012
Mensajes
2.340
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!
 

superexperto

Beta
Verificación en dos pasos desactivada
Desde
1 Nov 2012
Mensajes
70
Y que servidores hay para alojar .js? Me podéis decir algunos? De verdad, muchííísimas gracias por esta gran ayuda!
 

Olvy

Eta
Verificación en dos pasos desactivada
Verificado por Whatsapp
Verificado por Binance
Desde
6 Sep 2012
Mensajes
1.340
Para alojar archivos .js te recomiendo google code que al ser de google se supone es bueno para esto ...
 

paseo

Gamma
SEO
Verificación en dos pasos activada
Verificado por Whatsapp
Desde
16 May 2012
Mensajes
417
Se podria hacer alguna modificación en este mismo código para que el popup fuera under?
 

el jefecilo

Beta
Verificación en dos pasos desactivada
Desde
22 Dic 2014
Mensajes
45
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:
 

el jefecilo

Beta
Verificación en dos pasos desactivada
Desde
22 Dic 2014
Mensajes
45
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
 

comors

Gamma
Verificación en dos pasos desactivada
Verificado por Whatsapp
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Desde
16 Ago 2014
Mensajes
324
Demasiado código para algo tan simple. Cambiaría las cookies por sessionStorage
 

Johanko

No recomendado
Verificación en dos pasos desactivada
Desde
24 Abr 2013
Mensajes
767
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.
 

morenofeo

Alfa
Verificación en dos pasos desactivada
Desde
6 Oct 2015
Mensajes
28
Por favor, ten en cuenta 📝 que si deseas hacer un trato 🤝 con este usuario, está baneado 🔒.
Buen aporte me a Funcionado perfecto ME A Encantado Muy Bien Sigue adelante
 

¡Regístrate y comienza a ganar!

Beneficios

  • Gana dinero por participar
  • Gana dinero por recomendarnos
  • Descubre ofertas de empleo diariamente
  • Negocios seguros
  • ¡Información premium y más!

Acceder

¿Ya tienes una cuenta? Accede aquí

Arriba