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>
source to share
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.
source to share
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.
source to share