Mythri 07-23-2011, 05:37 AM Hi All,
I am very new to javascript.
I want to open a pop up window automatically on the date when i have mentioned in the function, means if the date is equal to 24/07/2011, then when i open the website open the pop up window...
How to do that? Please suggest
Old Pedant 07-23-2011, 05:57 AM And what do you do about popup blockers???
This kind of popup is *EXACTLY* the kind that the blockers will most aggressively block. So most of your users won't then see it, even if your code works.
But having said that:
var now() = getDate()
// month numbers are 0 through 11 in JS coding, not 1 through 12, so:
if ( now.getFullYear() == 2011 && now.getMonth() == 6 && now.getDate() == 24 )
{
window.open( "yourURL", "_blank", "height=500,width=800" );
}
But, as I said, don't be surprised if 80% of your users never see the popup.
Have you considered using a pop-ON instead??
Mythri 07-23-2011, 06:15 AM ohh .. I havent thought about pop up blockers. How do i bypass that? is there any other way to do that i mean on click button it should open?
and if i put this code within <head> </head> will i be able to open?
as i am very new to javascript please help me
Mythri 07-23-2011, 06:25 AM and i have placed this code within head
<script type="text/javascript">
var now() = getDate()
// month numbers are 0 through 11 in JS coding, not 1 through 12, so:
if ( now.getFullYear() == 2011 && now.getMonth() == 6 && now.getDate() == 24 )
{
window.open( "yourURL", "_blank", "height=500,width=800" );
}
</script>
in var now() = getDate(), it is giving error , it says , syntax error. please kindly help me
Mythri 07-23-2011, 06:34 AM Please help me
Mythri 07-23-2011, 07:46 AM Anybody can help me on this please..
Philip M 07-23-2011, 08:54 AM in var now() = getDate(), it is giving error , it says , syntax error. please kindly help me
As now is a variable it should be now without any brackets. The getDate() method returns the day of the month (from 1 to 31) for the specified date, according to local time. This method is always used in conjunction with a Date object. The method you are wanting is now = new Date(); Old Pedant seems to be having an off-day. :p
But please pay attention to what you have been told - pop-up blockers (I would say implemented by default on 98% of browsers) will prevent your pop up from appearing. You cannot by-pass that. It it were possible to do so, the blocker would be pointless.
Rather than a pop-up you could use a <div> which is made visible on the desired date.
<div id = "mydiv" style ="display:none">Place the message here - style the text using css</div>
<script type = "text/javascript">
var now = new Date();
if (now.getFullYear() == 2011 && now.getMonth() == 6 && now.getDate() == 24) {
document.getElementById("mydiv").style.display="block";
}
</script>
Note that the script must be run after the <div> has been created. Either by placing the script at the end of your HTML page before the </body> tag, or by wrapping it in a function called by <body onload = ...
Quizmaster: In maths, what is 20 minus eight?
Contestant: Pass
grid_ 07-23-2011, 11:03 PM You could use a Jquery UI dialog instead of a javascript popup. They won't get a block with several popupblockers. Go to http://www.jqueryui.com for more details.
Greets,
grid
Old Pedant 07-23-2011, 11:13 PM Sorry about the idiocy with getDate() ... I had just been answering a question about ASP coding and my head was in the wrong place.
Exactly as Philip suggested, here's how you can do a POPON that the popup blockers won't see:
<html>
<head>
<style type="text/css">
div#POPON {
display: none;
position: absolute;
top: 100px; left: 100px;
height: 300px; width: 500px;
border: solid blue 3px;
background-color: lightblue;
color: blue;
font-size: medium;
}
</style>
<script type="text/javascript">
function checkPopon( )
{
var now = new Date();
// remember: 6 is July, since months are numbered 0 to 11
if (now.getFullYear() == 2011 && now.getMonth() == 6 && now.getDate() == 24)
{
document.getElementById("POPON").style.display="block";
}
}
</script>
</head>
<body onload="checkPopon()">
<!-- the POPON div needs to be placed right after the BODY tag (or at the end of the body) -->
<div id="POPON">
<center><h2>GREETINGS!</h2></center>
Today is your lucky day!
</div>
... then the rest of your page ...
</body>
</html>
Mythri 07-24-2011, 08:37 AM Thanks you very much!. Thanks a ton.
I have a small doubt, now it opens o that date which i have mentioned in the function, i mean 24/07/2011.
Is it possible to display continuously i mean the date which i mention and after that? for example, on and after the date 24/07/2011.
Please guide me :(
Philip M 07-24-2011, 08:52 AM Thanks you very much!. Thanks a ton.
I have a small doubt, now it opens o that date which i have mentioned in the function, i mean 24/07/2011.
Is it possible to display continuously i mean the date which i mention and after that? for example, on and after the date 24/07/2011.
Please guide me :(
Replace the function checkPopon() with the following:-
function checkPopon() {
var now = new Date();
var eventDate = new Date("July 24, 2011");
if (now >= eventDate) {document.getElementById("POPON").style.display = "block"}
}
Mythri 07-24-2011, 09:07 AM Thanks a ton ton ! it really helped me. I wanted to upload the site for my client and i did not receive the payment yet, so wanted to have some kind of control. Hope it will help me doing that. Thanks a ton. Please suggest if any other controls i can have better than this.
Philip M 07-24-2011, 09:17 AM Thanks a ton ton ! it really helped me. I wanted to upload the site for my client and i did not receive the payment yet, so wanted to have some kind of control. Hope it will help me doing that. Thanks a ton. Please suggest if any other controls i can have better than this.
I am not sure what you mean. If the client has not paid, simply do not upload the site. Or if you have already uploaded it, delete it if the client does not pay within the contract terms. But it is not advised to add some sort of message to the site which is not approved by the client.
Mythri 07-24-2011, 09:27 AM Thanks a lot for the suggestion.
aww coconuts 07-27-2011, 01:39 AM Sorry about the idiocy with getDate() ... I had just been answering a question about ASP coding and my head was in the wrong place.
Exactly as Philip suggested, here's how you can do a POPON that the popup blockers won't see:
<html>
<head>
<style type="text/css">
div#POPON {
display: none;
position: absolute;
top: 100px; left: 100px;
height: 300px; width: 500px;
border: solid blue 3px;
background-color: lightblue;
color: blue;
font-size: medium;
}
</style>
<script type="text/javascript">
function checkPopon( )
{
var now = new Date();
// remember: 6 is July, since months are numbered 0 to 11
if (now.getFullYear() == 2011 && now.getMonth() == 6 && now.getDate() == 24)
{
document.getElementById("POPON").style.display="block";
}
}
</script>
</head>
<body onload="checkPopon()">
<!-- the POPON div needs to be placed right after the BODY tag (or at the end of the body) -->
<div id="POPON">
<center><h2>GREETINGS!</h2></center>
Today is your lucky day!
</div>
... then the rest of your page ...
</body>
</html>
Is there anyway to make this have multiple dates, or like only on the 3rd of any month? I just fouind this place and let me say, i signed up and will be bookmarking. Im new to coding and looooove it
jmrker 07-27-2011, 01:49 AM Is there anyway to make this have multiple dates, or like only on the 3rd of any month? I just fouind this place and let me say, i signed up and will be bookmarking. Im new to coding and looooove it
Change following line
/* from:
if (now.getFullYear() == 2011 && now.getMonth() == 6 && now.getDate() == 26)
*/
// to:
if (now.getDate() == 3)
|
|