Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open new tab(window) by clicking a link in jquery [duplicate]

I have a web app that displays rows with go and delete buttons.

If a user clicks go, it should open new tab/window with url built from the row's data.

how can I do this in jquery? What I'm doing is :

$('.go').click( function () {    var wid = {{ wid|tojson|safe }};    var sid = $(this).prop('id');    url = $script_root + '/' + wid + '/' + sid;     // go to url }); 

some update:

What I'm really tring to accomplish is dynamically update href of an <a> element.

<a id="foo" href="#">foo</a> <script type="text/javascript> $('#foo').click( function() {   $(this).prop('href', 'http://www.google.com/'); }); </script> 

which doesn't work (fiddle :http://jsfiddle.net/6eLjA/)

like image 656
thkang Avatar asked Mar 01 '13 08:03

thkang


1 Answers

Try this:

window.open(url, '_blank'); 

This will open in new tab (if your code is synchronous and in this case it is. in other case it would open a window)

like image 192
karaxuna Avatar answered Sep 22 '22 03:09

karaxuna