How do I pop up the a page in fancyBox when the page loads?

When my page loads, if the user is not logged in I need to pop up the login screen in fancyBox. Apparently some users are complaining that they don't know how to click the "log in" link.

Code for the "log in" link looks like this and works perfectly when clicked:
<div class="login-txt">
<a href="ShowLogin.php" id="loginLink" class="fancybox-login">Log In</a>
</div>

Open in new window


Handling the "is it logged in?" condition is trivial in PHP, so I'll just show the JavaScript that is failing to do the same thing as clicking that link.
<script type="text/javascript">$(document).ready(function (){
			//$('a[href="ShowLogin.php"]').fancybox();
			$("loginLink").fancybox();
		});</script>

Open in new window


A breakpoint in Firebug shows that the line is being executed.  And the Firebug console reports no JS error.

What should I be doing instead to get the page, upon loading, to "click" the Log In link?

Thanks!
LVL 32
Daniel WilsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
$(function(){
    $("#loginLink").fancybox().trigger('click');
})

Open in new window

0
Daniel WilsonAuthor Commented:
Closer, but not quite.  As I step through it, the form darkens ... as if ... the fancybox'ed form will display ... but then it clears.  If I just let it run, I don't actually see it darken.
0
GaryCommented:
Have you got a link to the page?
Maybe it needs a small delay to give the form a chance to load.

$("#loginLink").fancybox().delay(1000).trigger('click');

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Daniel WilsonAuthor Commented:
0
Daniel WilsonAuthor Commented:
Hold on ... clicking the Log In link isn't working any more either.  I broke something :(
0
Daniel WilsonAuthor Commented:
Apparently adding the id to the link broke the fancyBox action.  But it's the only way I know to access the link via JavaScript. :(
0
GaryCommented:
In your question you had an ID in the anchor tag but on the site there is no ID
0
GaryCommented:
Change the code to

$(".fancybox-login").fancybox().trigger('click');

Open in new window

0
Daniel WilsonAuthor Commented:
aha ... you got me within 1 tweak of it!
$(".fancybox-login").trigger('click');
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GaryCommented:
I wasn't close, the code was correct.
0
Daniel WilsonAuthor Commented:
Gary's was crazy close ... but for completeness I'm giving the correction.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.