Reputation: 1
i have a link Auto click
and jquery code for automatically click link when page has been loaded
$('#links').click();
but when i test this. Browser has prevent popup ( links )
how can i fix it???
Upvotes: 0
Views: 222
Reputation: 74738
May be this could help you: http://jsfiddle.net/LX7xs/
$(window).click(function(){
alert('click triggered.');
}).trigger('click');
With this script when page load first time .trigger('click')
gets fired and alert pops. Although window holds the click event yet.
Upvotes: 0
Reputation: 805
$('#links').click(function(event){
event.preventDefault();
yourFunction();
});
If you're thinking of doing something sneaky with this, I would advise against it. It would seem you're trying to trigger popups with your function.
If you're doing this out of the kindness of your heart, then I can't see why the attribute "target=_blank" wouldnt do the trick.
What the above code allows you to do, is to prevent the browser from doing what it usually does when you click the link. It will then wait for your JS to do whatever it wants to do.
I would suggest showing the remaining code in your function if you want anymore help than that.
Upvotes: 0
Reputation: 519
The problem is not with your jquery but with the way your link/button behaves. You cannot force the browser to enable popups, it is a client side security feature. Perhaps you could instead use an anchor tag and set target property to blank. This should open the link in a new tab/window.
Upvotes: 1