Need some javascript help
28-09-2004, 09:09
|
#1
|
|
Inactive
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
|
Need some javascript help
I have a popup window which uses an animated DIV that a customer want's to only show on certain day's, I've got the day of the week (number) from using
Code:
<SCRIPT LANGUAGE="JavaScript">
today = new Date();
day = today.getDay();
</SCRIPT>
So for example, if day=2,5 or 7 then I want it to do the following:
Code:
<script language="JavaScript">
if (document.all) {
w = document.body.clientWidth;
h = document.body.clientHeight;
}
else if (document.layers) {
w = window.innerWidth;
h = window.innerHeight;
}
var popW = 517, popH = 417;
var leftPos = (w-popW)/2;
document.write('<div id="dropin" style="z-index:12;position:absolute;visibility:hidden;left:'+leftPos+'px;top:100px;width:517px;height:417px;filter:Shadow(color=gray,offX=-5,offY=-5,direction=145)">');
</script>
<table width="500" border="0" cellpadding="5" cellspacing="1" bgcolor="#41738D">
<tr>
<td height="160" valign="top" bgcolor="#F0F5F7">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr><td><div align="right"><a href="#" onClick="dismissbox();return false"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Close<strong>
[ X ] </strong></font></a></div></td></tr></table>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td valign="top"><p>
<p align="center"><strong><font color="#FF6600">POP UP WINDOW CONTENTS GO IN HERE<br>
<br><script language=javascript>document.write(day);</script>
</font></strong></p> </td>
</tr>
</table>
</td>
</tr>
</table>
</div>
And if the day isn't one of them values .. not show it...
thanks.
|
|
|
28-09-2004, 10:49
|
#2
|
|
Inactive
Join Date: Jun 2003
Location: UK
Posts: 4,988
|
Re: Need some javascript help
Basic syntax is as below:
Code:
<SCRIPT LANGUAGE="JavaScript">
today = new Date();
day = today.getDay();
if (day == "2") {
document.write ("Launch popup")
}
else {
document.write ("don't launch popup")
}
</script>
|
|
|
28-09-2004, 11:01
|
#3
|
|
Inactive
Join Date: Jun 2003
Location: UK
Posts: 4,988
|
Re: Need some javascript help
Ok my revised code:
index.htm
//File that loads the script
Code:
<SCRIPT LANGUAGE="JavaScript">
today = new Date();
day = today.getDay();
if (day == "2") {
window.open('newwindow.htm','','scrollbars=yes,resizable=no');
}
</script>
newwindow.htm
//contents of the popup
Code:
<SCRIPT LANGUAGE="JavaScript">
if (document.all) {
w = document.body.clientWidth;
h = document.body.clientHeight;
}
else if (document.layers) {
w = window.innerWidth;
h = window.innerHeight;
}
var popW = 517, popH = 417;
var leftPos = (w-popW)/2;
document.write('<div id="dropin" style="z-index:12;position:absolute;visibility:hidden;left: '+leftPos+'px;top:100px;width:517px;height:417px;filter:Shadow(color=gray,offX=-5,offY=-5,direction=145)">');
</script>
<table width="500" border="0" cellpadding="5" cellspacing="1" bgcolor="#41738D">
<tr>
<td height="160" valign="top" bgcolor="#F0F5F7">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr><td><div align="right"><a href=javascript:void(top.close());><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Close<strong>
[ X ] </strong></font></a></div></td></tr></table>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td valign="top"><p>
<p align="center"><strong><font color="#FF6600">POP UP WINDOW CONTENTS GO IN HERE<br>
<br><script language=javascript>document.write(day);</script>
</font></strong></p> </td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</script>
|
|
|
28-09-2004, 11:02
|
#4
|
|
Inactive
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
|
Re: Need some javascript help
Quote:
|
Originally Posted by Caspar
Basic syntax is as below:
Code:
<SCRIPT LANGUAGE="JavaScript">
today = new Date();
day = today.getDay();
if (day == "2") {
document.write ("Launch popup")
}
else {
document.write ("don't launch popup")
}
</script>
|
So I have to stick the whole of the extra javascript and HTML in document.writes? Parsing that is going to be a nightmare .. think I'll tell them it can't be done with JS and coax them into letting me do it with ASP
The popup isn't actually a new window as such, it's a div and it's part of the page so it can't appear in a new window.
|
|
|
28-09-2004, 11:07
|
#5
|
|
Inactive
Join Date: Jun 2003
Location: UK
Posts: 4,988
|
Re: Need some javascript help
Yeah, i decided not to encapsulate your code into doc.writes aswell!!!
so I opted for a new window angle, see above
|
|
|
28-09-2004, 14:02
|
#6
|
|
Inactive
Join Date: Jun 2003
Age: 44
Posts: 14,750
|
Re: Need some javascript help
Also, if you want to do 2 or 5 or 7, you can do it like this:
if ((var ==2) || (var == 5) || (var == 7))
{
//display window
}
Just for reference, if you want two vars to be certain values, you can use && for and
|
|
|
28-09-2004, 14:13
|
#7
|
|
Inactive
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
|
Re: Need some javascript help
It's ok, now he's decided he wants the DIV to show based on a cookie ... so this can be closed I guess, sorry for wasting your time
|
|
|
28-09-2004, 15:27
|
#8
|
|
Inactive
Join Date: Jun 2003
Location: UK
Posts: 4,988
|
Re: Need some javascript help
np
|
|
|
28-09-2004, 17:38
|
#9
|
|
Inactive
Join Date: Mar 2004
Services: BB:M, TV:XL, Phone:M, Loyalty
Posts: 2,516
|
Re: Need some javascript help
If it's one of those blasted DIV pseudo popups, tell him it won't win any friends!
http://www.kephyr.com/popupkillertest/index.html - Test your browser and blocker against many popups and variants here - if you can get a clean slate against some of the obscure variants, you're probably running Mozilla!
|
|
|
28-09-2004, 18:06
|
#10
|
|
Inactive
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
|
Re: Need some javascript help
Quote:
|
Originally Posted by Matth
If it's one of those blasted DIV pseudo popups, tell him it won't win any friends!
http://www.kephyr.com/popupkillertest/index.html - Test your browser and blocker against many popups and variants here - if you can get a clean slate against some of the obscure variants, you're probably running Mozilla!
|
Doesn't matter whether it wins him any friends or not, it's only going to advertise his services, on his own site and as he's a paying customer, he can have the moon on a stick if he's willing to part with the cash for it.
|
|
|
28-09-2004, 20:53
|
#11
|
|
Inactive
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 46
Posts: 6,343
|
Re: Need some javascript help
Quote:
|
Originally Posted by Caspar
Yeah, i decided not to encapsulate your code into doc.writes aswell!!!
so I opted for a new window angle, see above 
|
He needs to be using HTML+CSS (DHTML) for this, if I've read between the lines correctly.
Just like those annoying adverts that popup over the text of the page you're reading on some sites.
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 19:24.
|