JavaScript and client side scripting.
Moderator: General Moderators
webdev
Forum Commoner
Posts: 25 Joined: Tue Jun 05, 2007 2:07 am
Post
by webdev » Tue Jun 19, 2007 9:05 pm
Hi guys,
Code: Select all
var expDays = 1; // number of days the cookie should last
var page = "popwin.html";
var windowprops = "width=300,height=300,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
} else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);
window.open(page, "", windowprops);
} else {
count++;
SetCookie('count', count, exp);
}
}
window.onload=checkCount;
How to when you have a popup window which opens on your homepage every time a visitor returns?
Any helps that would be great!
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Tue Jun 19, 2007 9:08 pm
Eww. Are you serious?
I believe window.open or something. I'll check.
Edit : Yea, window.open().
Last edited by
superdezign on Tue Jun 19, 2007 9:10 pm, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jun 19, 2007 9:09 pm
"onload" is typically all that's required, provided their browser doesn't block automatic pop-ups.
Your pop-up will open happen if "count" is found to be null, from GetCookie().
webdev
Forum Commoner
Posts: 25 Joined: Tue Jun 05, 2007 2:07 am
Post
by webdev » Wed Jun 20, 2007 12:47 am
Well, at the moment, the pop up window doesn't open.
superdezign - do you mean window.open=checkCount; in javascript and what about html?
Feyd - yeah but doesn't work. Can you me give the code of this please?
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Wed Jun 20, 2007 3:14 am
Pop-up windows launched from a non-interactive event (eg document loading) are always blocked by pop-up blockers. Some blockers even stop windows opened by interactive events like buttons.
Long story short: Pop ups aren't guaranteed to open regardless of how you launch them. Do not rely on it opening for all users because it just won't.
webdev
Forum Commoner
Posts: 25 Joined: Tue Jun 05, 2007 2:07 am
Post
by webdev » Wed Jun 20, 2007 3:25 am
Thanks, Gente. Your examples talking about when the user click the button, the small window will be pop up.
I was looking for popup window that only displays the first time the visitor enters my site. But now it's not working!
webdev
Forum Commoner
Posts: 25 Joined: Tue Jun 05, 2007 2:07 am
Post
by webdev » Wed Jun 20, 2007 3:27 am
I understand, onion2k but my client really want this. This is for promotion for short term.
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Wed Jun 20, 2007 6:09 am
Popups never mean promotion. Popups mean annoyance.
Try creating a pseudo window on the actual website. Just a big absolutely positioned div that has an "X" in the corner that makes the div go away.
webdev
Forum Commoner
Posts: 25 Joined: Tue Jun 05, 2007 2:07 am
Post
by webdev » Wed Jun 20, 2007 7:48 pm
superdezign, do you have a code for pseudo window? If yes, can you please give me a code? Also, show me the sample of this.
Thanks.
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Wed Jun 20, 2007 7:57 pm
It's honestly no more than what I've described to you. An absolutely positioned div. It's all CSS and JavaScript, and the JavaScript does nothing other than display it and allow it to be hidden. It's a simple creation.
I'll write a little tutorial on making one, but in the meantime, you can probably do this yourself. You need position:absolute, possibly z-index, onLoad, and onClick. In it's simplest form, it's a quick addition.
webdev
Forum Commoner
Posts: 25 Joined: Tue Jun 05, 2007 2:07 am
Post
by webdev » Wed Jun 20, 2007 8:49 pm
Ok then. I don't know what do you mean that but I will try to this as best as possible. Also I haven't heard pseudo window before.
In fact, I am sure the javascript scripting is work but the pop-up window doesn't disappear.
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Wed Jun 20, 2007 9:22 pm
Pseudo basically just means "fake."
And you'd have a hidden div, and onload, you'd make it displayed, and when someone clicked the "X," it'd be hidden again.
webdev
Forum Commoner
Posts: 25 Joined: Tue Jun 05, 2007 2:07 am
Post
by webdev » Wed Jun 20, 2007 9:43 pm
Oh really. Bit like first visitor pop-up window.
Well, I have to find the code for this because I haven't done this before.