2010-04-13 10 views
2

Avec l'aide de vous les gars, j'ai maintenant un script qui fonctionne comme un charme. La seule chose dont j'ai besoin maintenant, c'est le script pour ouvrir l'URL dans un nouvel onglet/fenêtre.jQuery cliquez sur _blank

$(document).ready(function() { 
    $("#onskeliste li").click(
    function() 
    { 
     window.location = $(this).attr("url"); 
     return false; 
    }); 
    $('#onskeliste li a').click(function(e) { 
     e.stopPropagation(); 
    }); 

})(jQuery); 

Pouvez-vous m'aider avec ceci? :-)

+0

J'essayé d'utiliser: window.location = $ (this) .attr ("url"); this.target = "_blank"; Mais cela n'a pas fonctionné ...:/ –

Répondre

13

Au lieu d'utiliser window.location, vous devez utiliser window.open() pour ouvrir une nouvelle fenêtre (ou un nouvel onglet) au lieu de charger l'URL dans l'actuelle.

Window open() Method

+0

window.open ($ (this) .attr ("url")); Cela a fonctionné! Je vous remercie! –

4
$(function(){ 
    $('a.new-window').click(function(){ 
     window.open(this.href); 
     return false; 
    }); 
}); 
0

Try this ...

$(document).ready(function() { 
    $("#onskeliste li").click(
    function() 
    { 
     window.open($(this).attr("url")); 
     return false; 
    }); 
    $('#onskeliste li a').click(function(e) { 
     e.stopPropagation(); 
    }); 

})(jQuery); 
0
$(document).ready(function() { 
    $("#onskeliste li").click( 
    function() 
    { 
     e.preventDefault(); 
     window.open($(this).attr('url')); 
    }); 
    $('#onskeliste li a').click(function(e) { 
     e.preventDefault(); 
     window.open($(this).attr('url')); 
    }); 

})(jQuery);