Reputation: 1668
I have this JavaScript which opens new page:
$(document).ready(function () {
//$('a[id$="lnkHidden"]').trigger("click"); // Not sure if this is actually necessary
$('table[id$="dataTable"]').find("tbody").on("click", "tr", function () {
$(this).find('a[id$="lnkHidden"]').trigger("click");
});
});
This is the button which is called by the JS script:
<h:commandLink id="lnkHidden" action="#{bean.pageRedirect}" style="text-decoration:none; color:white; display:none">
</h:commandLink>
After I click on a table row I get this error message:
too much recursion [Break On This Error] ...,c=l.length;c--;)(f=l[c])&&(v[d[c]]=!(y[d[c]]=f));if(i){if(o||e){if(o){for(l=[],...
Can you help me to fix this?
Upvotes: 1
Views: 408
Reputation: 71908
Instead of triggering synthetic click events, you could just change the current URL directly:
$(document).ready(function () {
$('table[id$="dataTable"]').find("tbody").on("click", "tr", function () {
var links = $(this).find('a[id$="lnkHidden"]');
if(links.length && links[0].href) {
window.location.href = links[0].href;
}
});
});
Upvotes: 1
Reputation: 2434
You can cut the infinite loop with those changes from your original code
.trigger("click", [ true ])
function(event, simulated)
simulated || $(this).find('a[id$="lnkHidden"]').trigger("click", [ true ]);
However that event triggering and that kind of selectors are not recommended.
Upvotes: 1