Spooky 08-02-2002, 07:37 PM A friend of mine gave me this bit of script, I spent hours and hours trying to get it working. He claims it works on his PC fine (WIN 2000 with IE6) but it don't work on mine (Win 95 IE4)
The problem is:
If the line if(document.cookie=="") is left as
is, nothing happens and there is no cookie
in the temp. internet files folder.
If that line is changed to if(document.cookie!="")
then the cookie appears in the temp. internet files
folder OK, but the popup appears every time!
Sorry if i'm being stupid but I haven't done much JavaScript...
Cheers for any advice here.
<SCRIPT LANGUAGE="JavaScript">
<!--
function openWindow(winfile)
{
window.open(winfile,'','resizable=yes,scrollbars=yes,toolbar=no,width=680,height=450')
}
function popUp()
{
expireDate=new Date
expireDate.setSeconds(expireDate.getSeconds()+60)
beenHere="hello"
if(document.cookie=="")
{
window.open('popup.htm',"",'width=320,height=260')
document.cookie="beenHere="+beenHere+";expires=" +expireDate.toGMTString()
}
}
//-->
</SCRIPT>
</HEAD>
<BODY TEXT="NAVY" BGCOLOR="#FFFFCC" LINK="BLUE" VLINK="PURPLE" ALINK="RED" onLoad=popUp()>
Mrs G 08-02-2002, 08:10 PM I have attached a text file with a script for "popup once"
Might be what you're after, works on my site.
Spooky 08-03-2002, 01:06 AM Thanks Mrs G,
Your reply was appreciated. Downloaded the attachment 5 times (Doh!) before I worked out how to save the source on my Hdd.
The code seems Mega more complex than the original, but then that is maybe the problem here with so many platforms and O/S out there... I will analyse and try it out tomorrow.
As a footnote, the original script was given to me by a college tutor as part of an advanced web programming course - A friend and all but I still await a solution, cause it don't work as given!
Blessu og tak fra Island
A1ien51 08-03-2002, 05:32 AM this is what I use....
<html>
<head>
<title>PopUpScript</title>
<script>
function PopUp(PopUpUrl){
var ScreenWidth=window.screen.width;
var ScreenHeight=window.screen.height;
var movefromedge=0;
placementx=(ScreenWidth/2)-((400)/2);
placementy=(ScreenHeight/2)-((300+50)/2);
WinPop=window.open(PopUpUrl,"","width=400,height=300,toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0, left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
}
function CheckCookie(PopName) {
var ReturnVal = "";
var PopV = PopName + "=";
if (document.cookie.length > 0) {
OffSet = document.cookie.indexOf(PopV);
if (OffSet != -1) {
OffSet += PopV.length;
End = document.cookie.indexOf(";", OffSet);
if (End == -1)
End = document.cookie.length;
ReturnVal=unescape(document.cookie.substring(OffSet, End));
}
}
return ReturnVal;
}
function LOadIt(){
if (CheckCookie("Popped")==""){
PopUp('http://www.A1ien51.8k.com');
document.cookie="Popped=yes";
}
}
</script>
</head>
<body onload="LOadIt()">
</body>
</html>
this code can be generated on here: http://www10.brinkster.com/A1ien51/scripts/PopUpWinGenV3.htm
A1ien51
Mrs G 08-03-2002, 10:14 AM I tried the script you posted above and nothing happens.
This is because there are no cookie functions
boywonder 08-03-2002, 06:34 PM Spooky if you want to use session only cookies as indicated by your topic, then you don't need to expire the cookie. It will last until the end of the session. The following should work just fine provided there are no other cookies from that domain:
function popUp(){
var beenHere="hello"
if(document.cookie==""){
window.open('popup.htm',"",'width=320,height=260')
document.cookie="beenHere="+beenHere;
}
}
If there are other cookies then document.cookie obviously won't be empty and you'll need to check for that specific cookie instead. Post back if you still have problems.
With other cookies:
<script type="text/javascript" language="JavaScript">
getCookie = document.cookie;
function getTag(name) {
index = getCookie.indexOf(name + "=");
if (index == -1) return null;
startVal = getCookie.indexOf("=", index) + 1;
finishVal = getCookie.indexOf(";", startVal);
if (finishVal == -1) finishVal = getCookie.length;
return unescape(getCookie.substring(startVal, finishVal)); }
if (!getTag("firstVisit")) {
window.open('popup.htm',"",'width=320,height=260');
document.cookie = "firstVisit=true";
}
</script>
Spooky 08-06-2002, 12:01 AM Hi all,
My thanks also to Alien51, boywonder and Pooh for their suggestions. They will all be tried for an effective solution on my little community (charity) site.
So far Mrs G's solution works out (but I'm working on the timer as it's not quite right for me...) Just a shame the original short script don't work!
Cheers from JavaScript newbie! :) :o :thumbsup:
Explain your timer requirements
|
|