Description:

In this article, I will explain how to open external links in new tab using Jquery.

If we want to open links in new tab, use target attributes.

target = _blank – it will open link in new tab.

We can set target attributes for the links by the below code.

$('a').attr("target", "_blank");

Example program:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("a").click(function () {
                $('a').attr("target", "_blank");
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <a href="http://www.jqueryjohn.com/">Jquery</a>
    </div>
    </form>
</body>
</html>


Open external links in new tab using jquery, open links in new window, open all links in new tab using jquery

0 comments:

Post a Comment

 
Top