I have a problem with faking an anchor click via jQuery: Why does my thickbox appear the first time I click on the input button, but not the second or third time?
Here is my code:
<input onclick="$('#thickboxId').click();" type="button" value="Click me" />
<a id="thickboxId" href="myScript.php" class="thickbox" title="">Link</a>
It does always work when I click directly on the link, but not if I try to activate the thickbox via the input button. This is in FF. For Chrome it seems to work every time. Any hints?
If you don't need to use JQuery, as I don't. I've had problems with the cross browser func of
.click()
. So I use:JQuery('#left').triggerHandler('click');
works fine in Firefox and IE7. I haven't tested it on other browsers.If want to trigger automatic user clicks do the following:
Using Jure's script I made this, to easily "click" as many elements as you want.
I just used it Google Reader on 1600+ items and it worked perfectly (in Firefox)!
Try to avoid inlining your jQuery calls like that. Put a script tag at the top of the page to bind to the
click
event:Edit:
If you're trying to simulate a user physically clicking the link, then I don't believe that is possible. A workaround would be to update the button's
click
event to change thewindow.location
in Javascript:Edit 2:
Now that I realize that Thickbox is a custom jQuery UI widget, I found the instructions here:
Instructions:
<a href>
)class="thickbox"
)href
attribute of the link add the following anchor:#TB_inline
In the
href
attribute after the#TB_inline
add the following query string on to the anchor:?height=300&width=300&inlineId=myOnPageContent
Change the values of height, width, and inlineId in the query accordingly (inlineID is the ID value of the element that contains the content you would like to show in a ThickBox.
#TB_inline?height=155&width=300&inlineId=hiddenModalContent&modal=true
) so that closing a ThickBox will require calling thetb_remove()
function from within the ThickBox. See the hidden modal content example, where you must click yes or no to close the ThickBox.I've recently found how to trigger mouse click event via jQuery.