Jquery open page in new tab
You can use the target
attribute in the a
tag to open the page in a new tab. Here is an example:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank">Open in new tab</a>
This will open the page in a new tab when the link is clicked.
Alternatively, you can use jQuery to achieve this. Here is an example:
<a rel="nofollow" target="_blank" href="https://www.example.com" id="open-in-new-tab">Open in new tab</a>
<script>
$(document).ready(function() {
$("#open-in-new-tab").click(function() {
window.open($(this).attr("href"), "_blank");
});
});
</script>
This code uses the click
event to listen for clicks on the link, and then uses the window.open
method to open the page in a new tab.
You can also use the attr
method to set the target
attribute of the link to _blank
:
<a rel="nofollow" target="_blank" href="https://www.example.com" id="open-in-new-tab">Open in new tab</a>
<script>
$(document).ready(function() {
$("#open-in-new-tab").attr("target", "_blank");
});
</script>
This will set the target
attribute of the link to _blank
, which will open the page in a new tab when the link is clicked.