Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   General IT Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=19)
-   -   Need some javascript help (https://www.cableforum.uk/board/showthread.php?t=18065)

Bifta 28-09-2004 09:09

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.

Caspar 28-09-2004 10:49

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>


Caspar 28-09-2004 11:01

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>


Bifta 28-09-2004 11:02

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.

Caspar 28-09-2004 11:07

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 ;)

punky 28-09-2004 14:02

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

Bifta 28-09-2004 14:13

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 :(

Caspar 28-09-2004 15:27

Re: Need some javascript help
 
np :)

Matth 28-09-2004 17:38

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!

Bifta 28-09-2004 18:06

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.

Richard M 28-09-2004 20:53

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.


All times are GMT. The time now is 00:51.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum