Getting a Lightbox to display after a short initial delay?

Discussion in 'Javascript' started by TazaTek, Dec 27, 2007.

  1. TazaTek

    TazaTek Guest

    Is there a way to get a lightbox to open up after a 5 second delay? I
    have a client that wants to make sure that people see his web-page
    before he annoys them with a popup ad.

    I've tried an onload=pause() routine, which is essentially what I
    need. The only thing I can't figure out is the correct syntax to get
    the lightbox to display.

    I've tried things like:
    document.write ('<input class="lbON" id="lbONAuto" type="hidden"
    url="http://www.domain.com/lightbox_body.html" > ');

    but that just makes a mess..... what am I missing? Without the pause
    routine, I just put the <input> tag below my body...

    Any help would be much appreciated.

    Thanks

    Matt
    TazaTek, Dec 27, 2007
    #1
    1. Advertising

  2. TazaTek

    Lee Guest

    TazaTek said:
    >
    >Is there a way to get a lightbox to open up after a 5 second delay? I
    >have a client that wants to make sure that people see his web-page
    >before he annoys them with a popup ad.
    >
    >I've tried an onload=pause() routine, which is essentially what I
    >need. The only thing I can't figure out is the correct syntax to get
    >the lightbox to display.
    >
    >I've tried things like:
    >document.write ('<input class="lbON" id="lbONAuto" type="hidden"
    >url="http://www.domain.com/lightbox_body.html" > ');
    >
    >but that just makes a mess..... what am I missing? Without the pause
    >routine, I just put the <input> tag below my body...
    >
    >Any help would be much appreciated.



    Once a page has loaded, using document.write() clobbers
    everything that was on the page, including any Javascript
    libraries.

    But if you're at the point of having clients, you probably
    already know that. It might help to see exactly what it is
    that you're trying.

    "an onload=pause() routine" isn't specific enough to know what
    sort of blunder you might be making.
    I'm afraid to ask what "pause()" does.


    --
    Lee, Dec 28, 2007
    #2
    1. Advertising

  3. TazaTek

    TazaTek Guest


    >
    > "an onload=pause() routine" isn't specific enough to know what
    > sort of blunder you might be making.
    > I'm afraid to ask what "pause()" does.
    >
    > --

    Good point. Here's the code in question.
    ----------

    <script language="JavaScript"><!--
    var howManySeconds = 2

    //--This is the function that pauses, then calls your custom
    function.
    function pause() {
    myTimer=setTimeout("whatToDo()",howManySeconds*1000)
    }

    //-- This is the function that's executed after the delay time is
    up.
    function whatToDo() {
    alert ("Times up.")
    document.write ('<input class=\"lbOn\" id=\"lbOnAuto\"
    type=\"hidden\" value=\"http://www.joereedsoldmyhome.com/lightbox/
    test_lightbox.html\">');
    }
    //--></script>

    <body onload="pause()">
    more html here...

    -------------------------

    Our shop is not a JS development house, but are doing this as a
    courtesy for a client,so please forgive our JS unfamiliarity.

    We're just trying to have the light box popup after a 5-10 second
    delay that will give the customer a chance to see who's site they are
    on first.

    Thanks
    Matt
    TazaTek, Dec 28, 2007
    #3
  4. TazaTek

    Lee Guest

    TazaTek said:
    >
    >
    >>
    >> "an onload=pause() routine" isn't specific enough to know what
    >> sort of blunder you might be making.
    >> I'm afraid to ask what "pause()" does.
    >>
    >> --

    >Good point. Here's the code in question.
    >----------
    >
    > <script language="JavaScript"><!--
    > var howManySeconds = 2
    >
    > //--This is the function that pauses, then calls your custom
    >function.
    > function pause() {
    > myTimer=setTimeout("whatToDo()",howManySeconds*1000)
    > }
    >
    > //-- This is the function that's executed after the delay time is
    >up.
    > function whatToDo() {
    > alert ("Times up.")
    > document.write ('<input class=\"lbOn\" id=\"lbOnAuto\"
    >type=\"hidden\" value=\"http://www.joereedsoldmyhome.com/lightbox/
    >test_lightbox.html\">');
    > }
    > //--></script>
    >
    ><body onload="pause()">
    >more html here...
    >
    >-------------------------
    >
    >Our shop is not a JS development house, but are doing this as a
    >courtesy for a client,so please forgive our JS unfamiliarity.
    >
    >We're just trying to have the light box popup after a 5-10 second
    >delay that will give the customer a chance to see who's site they are
    >on first.


    I would suggest that you redirect to a new page containing the
    lightbox code after your delay. The more complicated solution
    would be to write content into the innerHTML attribute of a DIV.


    --
    Lee, Dec 28, 2007
    #4
  5. TazaTek

    David Mark Guest

    On Dec 27, 7:30 pm, TazaTek <> wrote:
    > > "an onload=pause() routine" isn't specific enough to know what
    > > sort of blunder you might be making.
    > > I'm afraid to ask what "pause()" does.

    >
    > > --

    >
    > Good point.  Here's the code in question.
    > ----------
    >
    >     <script language="JavaScript"><!--


    You clearly don't know what you are doing.

    >     var howManySeconds = 2
    >
    >     //--This is the function that pauses, then calls your custom
    > function.
    >     function pause() {
    >     myTimer=setTimeout("whatToDo()",howManySeconds*1000)
    >     }


    It doesn't pause. It defers the execution of "whatToDo" for 2 seconds
    (and creates a global myTimer variable for no good reason.)

    >
    >     //-- This is the function that's executed after the delay time is
    > up.
    >     function whatToDo() {
    >             alert ("Times up.")
    >             document.write ('<input class=\"lbOn\" id=\"lbOnAuto\"
    > type=\"hidden\" value=\"http://www.joereedsoldmyhome.com/lightbox/
    > test_lightbox.html\">');
    >     }
    >     //--></script>


    As noted, you can't do that after the page loads as you will wipe out
    the entire page.

    >
    > <body onload="pause()">
    > more html here...
    >
    > -------------------------
    >
    > Our shop is not a JS development house, but are doing this as a
    > courtesy for a client,so please forgive our JS unfamiliarity.


    You want to do your client a favor? Tell them to drop the silly
    Lightbox script. It uses about 80K of script to center an element.
    And if you aren't a "JS development house", then why are you trying to
    add script to the client's site? That doesn't seem courteous at all
    as you might unknowingly break something.

    >
    > We're just trying to have the light box popup after a 5-10 second
    > delay that will give the customer a chance to see who's site they are
    > on first.


    That's going to be even more annoying than showing the ad from the
    outset. I don't see any cookie checks, so I assume the ad will
    obscure the page n seconds after every refresh. If I were the
    customer, I would hit the back button and look elsewhere.

    If you feel you really must go through with this, you will have to
    read the documentation for the LightBox API (after you learn how to
    write JavaScript of course.) Surely it can be invoked without the
    ridiculous hidden input cue.
    David Mark, Dec 28, 2007
    #5
  6. -Lost said:
    > Response to David Mark <>:
    >
    >> You want to do your client a favor? Tell them to drop the silly
    >> Lightbox script. It uses about 80K of script to center an
    >> element. And if you aren't a "JS development house", then why are
    >> you trying to add script to the client's site? That doesn't seem
    >> courteous at all as you might unknowingly break something.

    >
    > Especially since it can be done in under 1KB of JavaScript and CSS
    > (combined), maybe 2KB. Add some "fading" code and it MIGHT hit 3KB.
    >

    Oh, you can do it in way less than 3k. If one of my widgets was 3k I'd
    go manage restaurants. Well, unless it was a really kick-ass widget, I
    suppose.

    ~A!

    --
    Anthony Levensalor


    Only two things are infinite, the universe and human stupidity,
    and I'm not sure about the former. - Albert Einstein
    My Pet Programmer, Dec 28, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    Long Delay in initial load of ASPX pages

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Aug 18, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    2,346
    r2thej151
    Aug 19, 2006
  2. Achu

    ASP.NET Initial delay solution.

    Achu, Oct 4, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    399
    Mark Rae
    Oct 5, 2006
  3. David Jackson
    Replies:
    1
    Views:
    289
    David Jackson
    Jul 23, 2008
  4. daniel
    Replies:
    8
    Views:
    122
    Thomas 'PointedEars' Lahn
    Aug 23, 2007
  5. sskk
    Replies:
    1
    Views:
    79
Loading...

Share This Page