'can I trigger click event onload

I am having anchor tag in my page. I like to trigger click event onload . Which means I wanna open this page "http://XXXXX.com" with new tab. Because I don't wanna popup blockers. Is there anyway to do this?

anchor attrs are given bellow

id="add_redirect"
href="http://XXXXX.com"
target="_blank"


Solution 1:[1]

Yeah, you can use a click event called onLoad(). Just use the setTimeout() method in jquery. It will call a click function without clicking it. Here is an example:

$("document").ready(function() {
    setTimeout(function() {
        $("#add_redirect").trigger('click');
    },10);
});

This will work for you when the page start to load and the time delay is 10ms which is negligible. Syntax has been corrected.

Solution 2:[2]

Try adding the following code in the page load

document.getElementById('add_redirect').click();

Solution 3:[3]

Using JQuery you can do that pretty easy. The earlier posted solution also work of course.

$(document).ready(function(){
 $("#add_redirect").trigger('click');
});

TRY DEMO

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyler2P
Solution 2 Acetilen
Solution 3 Acetilen