Anmol Dubey
Anmol Dubey

Reputation: 119

Open all external links in new window

I am using below code to covert all links pass through a php script - Now i want these links to pop open in a new window

 $( document ).ready(function() {  
$("a[href^='http']").each(function() {
 var value = $(this).attr('href');
 $(this).attr('href','<url>/pqr.php?'+value);
});

});

Links are opening in same window? How to get them opened in a new window.

Upvotes: 0

Views: 608

Answers (2)

Felk
Felk

Reputation: 8224

What about adding this:

$(this).attr("target","_blank");

EDIT: integrated like this:

$( document ).ready(function() {  
    $("a[href^='http']").each(function() {
        var value = $(this).attr('href');
        $(this).attr('href','<url>/pqr.php?'+value);
        $(this).attr("target","_blank");
    });
});

Works for me: http://jsfiddle.net/bontp6jk/

Upvotes: 1

stranger4js
stranger4js

Reputation: 267

How about this

$(document).ready(function(){
$("a").attr("target","_blank");

});

Upvotes: 0

Related Questions