2

With help from you guys I now have a script that works like a charm.. The only thing I need now, is the script to open the URL in a new tab/window.

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

})(jQuery);

Can you help me with this?? :-)

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
curly_brackets
  • 5,491
  • 15
  • 58
  • 102

4 Answers4

13

Instead of using window.location you should use window.open() to open a new window (or tab) instead of loading the URL in the current one.

Window open() Method

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
4
$(function(){
    $('a.new-window').click(function(){
        window.open(this.href);
        return false;
    });
});
Alex Ivasyuv
  • 8,585
  • 17
  • 72
  • 90
1
$(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);
Sunny
  • 6,286
  • 2
  • 25
  • 27
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);
Peter
  • 764
  • 7
  • 14