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="" > ');

    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.


    TazaTek, Dec 27, 2007
    1. Advertisements

  2. TazaTek

    Lee Guest

    TazaTek said:

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

    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
    1. Advertisements

  3. TazaTek

    TazaTek Guest

    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 pause() {

    //-- This is the function that's executed after the delay time is
    function whatToDo() {
    alert ("Times up.")
    document.write ('<input class=\"lbOn\" id=\"lbOnAuto\"
    type=\"hidden\" value=\"

    <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.

    TazaTek, Dec 28, 2007
  4. TazaTek

    Lee Guest

    TazaTek said:
    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
  5. TazaTek

    David Mark Guest

    You clearly don't know what you are doing.
    It doesn't pause. It defers the execution of "whatToDo" for 2 seconds
    (and creates a global myTimer variable for no good reason.)
    As noted, you can't do that after the page loads as you will wipe out
    the entire page.
    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.
    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
  6. -Lost said:
    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


    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
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.