Say I have an anchor link like:
<a id="page-contact" rel="shadowbox;width=640;height=400" href="/contact.php">link here</a>
How would I be able to open it from jquery i.e.
jQuery('#page-contact').click();
Obviously that calls the .click event but doesn't do the href if that makes sense.
The object of this is to actually open a lightbox not to change the page like window.location
Say I have an anchor link like:
<a id="page-contact" rel="shadowbox;width=640;height=400" href="/contact.php">link here</a>
How would I be able to open it from jquery i.e.
jQuery('#page-contact').click();
Obviously that calls the .click event but doesn't do the href if that makes sense.
The object of this is to actually open a lightbox not to change the page like window.location
Share Improve this question edited Mar 18, 2011 at 11:41 Alnitak 340k72 gold badges418 silver badges502 bronze badges asked Mar 18, 2011 at 11:09 ShaneShane 1,6034 gold badges26 silver badges54 bronze badges 2- Are you trying to navigate to the href or open the shadowbox? – Richard Dalton Commented Mar 18, 2011 at 11:22
- trying to open shadowbox – Shane Commented Mar 18, 2011 at 12:06
5 Answers
Reset to default 2To change your current page to the href
attribute of that element:
document.location.href = $('#page-contact').attr('href');
EDIT now that we have the real question, I think you can do this:
var obj = Shadowbox.setup('#page-contact');
Shadowbox.open(obj);
If you want to redirect the browser window to that target (specified in the href
attribute) do this:
window.location.href = $('#page-contact').attr('href');
if you want to trigger a click event on a jquery selection use:
('#page-contact').trigger('click')
Use either one of these to trigger a click
event:
$('#page-contact').click();
Or…
$('#page-contact').trigger('click');
If you’ve initialized the Shadowbox plugin correctly, the triggered click will cause the lightbox to appear.
Beat the geeks again!
I've done this and it works! :-)
Shadowbox.open({
content: '/content.php',
type: 'iframe',
title: 'Tags',
height:350,
width:450
});