3

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

Alnitak
  • 334,560
  • 70
  • 407
  • 495
Shane
  • 1,603
  • 4
  • 26
  • 54

5 Answers5

2

To 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);
Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • Close but that actually changes the page, it's not actually what I want to do. if you notice the rel="shadowbox" this should open a light box... – Shane Mar 18 '11 at 11:23
  • ok, was worth a try. The point was that it's Shadowbox has to do the real work. – Alnitak Mar 18 '11 at 12:07
1

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');
jAndy
  • 231,737
  • 57
  • 305
  • 359
  • Close but that actually changes the page, it's not actually what I want to do. if you notice the rel="shadowbox" this should open a light box... – Shane Mar 18 '11 at 11:24
0

if you want to trigger a click event on a jquery selection use:

('#page-contact').trigger('click')
Alex Bailey
  • 1,679
  • 10
  • 15
  • Close but that actually changes the page, it's not actually what I want to do. if you notice the rel="shadowbox" this should open a light box... So call the click - not change the page :) – Shane Mar 18 '11 at 11:27
  • If you want to trigger a click event on a jquery selection use: ('#page-contact').trigger('click'); – Alex Bailey Mar 18 '11 at 11:28
  • Again that only works if I have onclick="javascript:alert('2');" within the anchor tag – Shane Mar 18 '11 at 11:59
0

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.

Mathias Bynens
  • 144,855
  • 52
  • 216
  • 248
0

Beat the geeks again!

I've done this and it works! :-)

Shadowbox.open({
        content:    '/content.php',
        type:     'iframe',
        title:      'Tags',
        height:350,
        width:450
    });
Shane
  • 1,603
  • 4
  • 26
  • 54