Solved

How can I make a Lightbox load with the page's onLoad?

Posted on 2008-10-17
10
2,182 Views
Last Modified: 2012-05-05
I'm ready to hand in my web design title and go look for bricklaying jobs.  I need a Lightbox to load when the page loads.  I've tried adding the lightbox.js or some elements thereof to onLoad: no dice.  I've tried simulating a click of a link: no dice.  I simulate a link of a button with no problem, but that won't let me do the Lightbox.  How can I pass the rel attribute this way?

I'm ready to scream.
0
Comment
Question by:mrcoulson
  • 6
  • 4
10 Comments
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 22745351
There are a number of lightboxes available.
I use jQuery's balupton edition (http://plugins.jquery.com/project/jquerylightbox_bal) which has an autostart option.
0
 

Author Comment

by:mrcoulson
ID: 22759699
This looks promising.  I don't really know two nothings 'bout jQuery, though.  I'm trying this out.  Now let's say that my employer doesn't want the cool "jQuery Lightbox..." text in the right-hand corner of the window.  How do I eliminate that?

Jeremy
0
 

Author Comment

by:mrcoulson
ID: 22759818
Nevermind.  Got it.

<script type="text/javascript" src="jquery_lightbox/js/jquery.lightbox.packed.js?show_linkback=false"></script>
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:mrcoulson
ID: 22759851
But now how do I make it load automatically?  
0
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 22760344
By specifiying the start option and set it to true.
IE $("a.lightbox").lightbox( { "start":true });
0
 

Author Comment

by:mrcoulson
ID: 22760678
I guess this is where my understanding of jQuery falls apart.  Where does that code belong?

In good ol' JavaScript, I'd imagine doing something like that onLoad, like: <body onLoad="runTheFunctionThatLaunchesTheLightbox('theIdOfTheAnchorToBeSelectedForTheLightbox');">

Jeremy
0
 

Author Comment

by:mrcoulson
ID: 22760794
Okay, I'm beginning to see a little bit of how this works.

$("a.lightbox").lightbox( { "start":true });

$ means it's jQuery.

a.lightbox means it's an anchor with rel="lightbox".

I'm not sure about .lightbox.

"start":true sets some property called start to true.

So, I'm guessing the middle .lightbox is a reference to my particular anchor.  Right?  Wrong?  Maybe?
0
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 500 total points
ID: 22760852
You can put script just before the </body> ie
$(function() {
    $("a.lightbox").lightbox( { "start":true });
});

$(function() {}) is short-hand for DOM ready functionality

In this example the lightbox is bound to every A element with classname 'lightbox', and started directly.

Useful links : http://docs.jquery.com
<script type="text/javascript">
$(function() {
	$("a.lightbox").lightbox( { "start":true });
});
</script>

Open in new window

0
 

Author Comment

by:mrcoulson
ID: 22760902
Hey!  500 points for you!

Thanks for the answer and thanks for helping me get started with jQuery.  This is pretty cool stuff and it will give me something new to try when I start my new job next week.  Thanks!!

Jeremy
0
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 22760917
You're welcom, glad I could help
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how can i make 2 columns? 4 41
Access RV042 GUI / Browser Issues 25 49
forgetful about js objects 8 47
jquery tab header text 1 23
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question