JQuery follows the hyperlink with target = "_blank"

I am trying to open a hyperlink with target = "blank".

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(window).load(function() {
    $('a').click();
});
</script>
</head>

<body>
<a href="http://www.google.com" target="_blank">Report</a>
</body>
</html>

      

+2


source to share


4 answers


I used a hyperlink normal target = "_blank" on page 2 and had page2 processing the database.



0


source


Triggered events seem to only fire events that were associated with jQuery. Take a look at this modified example:



$(document).ready(function() {
    $('a').click(function(){
        alert('adf');
    });
    $('a').click();
});

      

+3


source


click()

creates an on-click event and binds it to the object. It doesn't actually trigger a click, it just creates a function that is executed after the user clicks if / when they want to do so.

What you are looking for is trigger()

one that allows you to simulate a click without actually being triggered by the user. Also, in most cases, you should have an ready

event instead of an event load

.

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(window).ready(function() {
    $('a').trigger('click');
});
</script>
</head>

<body>
<a href="http://www.google.com" target="_blank">Report</a>
</body>
</html>

      

Another note is that what you are trying to do may be blocked by pop-up blockers as they are designed to prevent the website from opening a new window on page load.

+2


source


Click, as per the jQuery docs ,

"Calls all functions that have been associated with this click event is executed."

This will not include opening a link.

I'm not sure how to do it otherwise. In fact, I am sure that this is not possible.

+2


source







All Articles