Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    92
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Open pop up window depending on date

    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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,537
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    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:
    Code:
    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??

  • #3
    New Coder
    Join Date
    Jan 2011
    Posts
    92
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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

  • #4
    New Coder
    Join Date
    Jan 2011
    Posts
    92
    Thanks
    8
    Thanked 0 Times in 0 Posts
    and i have placed this code within head

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

  • #5
    New Coder
    Join Date
    Jan 2011
    Posts
    92
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Please help me

  • #6
    New Coder
    Join Date
    Jan 2011
    Posts
    92
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Anybody can help me on this please..

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,016
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by Mythri View Post
    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.

    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.

    Code:
    <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
    Last edited by Philip M; 07-23-2011 at 09:48 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #8
    New Coder
    Join Date
    Jul 2011
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,537
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    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:

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

  • Users who have thanked Old Pedant for this post:

    Mythri (07-24-2011)

  • #10
    New Coder
    Join Date
    Jan 2011
    Posts
    92
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,016
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by Mythri View Post
    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:-

    Code:
    function checkPopon() {
    var now = new Date();
    var eventDate = new Date("July 24, 2011");
    if (now >= eventDate) {document.getElementById("POPON").style.display = "block"}
    }

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    Mythri (07-24-2011)

  • #12
    New Coder
    Join Date
    Jan 2011
    Posts
    92
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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.

  • #13
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,016
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by Mythri View Post
    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.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #14
    New Coder
    Join Date
    Jan 2011
    Posts
    92
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thanks a lot for the suggestion.

  • #15
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    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:

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


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •