Getting a Lightbox to display after a short initial delay?

T

TazaTek

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
 
L

Lee

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.


--
 
T

TazaTek

"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
 
L

Lee

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


--
 
D

David Mark

Good point.  Here's the code in question.

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

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

My Pet Programmer

-Lost said:
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
(e-mail address removed)

Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former. - Albert Einstein
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top