Solved

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

Posted on 2008-10-17
10
2,174 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now