Follow in Twitter & Facebook

Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools

Wednesday, August 15, 2012

Open hyperlink in new tab using jquery

In this article we will discuss how to open a hyperlink in new window or tab using jQuery or JavaScript. You can also check my last article on jQuery sample here. Also you can see some SharePoint articles, Jobs.

The javascript code to open hyperlink in new tab is below:

 <script type="text/javascript">
        $(function () {
            $("a").attr("target", "_blank");

This will open every links in a page in new window. But suppose you want it for a particular section then follow below code:
jQuery approach:

Add .js file to page as like below:

<script type="text/javascript" src=""></script>

Then write the script code like below:
<script type="text/javascript">
       $('.divclassname a').live('mouseover', function () {
           $(this).attr('target', '_blank');

<div class="divclassname">
<a href="" > SharePointDotNet</a>
<a href="" > Fewlines4Biju</a>

Here in the above schenerious, only SharePointDotNet link will open in new tab or window but Fewlines4Biju will not open in new tab. Because we have mention the div class name in the jQuery function.

0 on: "Open hyperlink in new tab using jquery"