单击jquery中的链接打开新选项卡(窗口) [英] open new tab(window) by clicking a link in jquery

查看:142
本文介绍了单击jquery中的链接打开新选项卡(窗口)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页应用,显示行 go 删除按钮。

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

如果用户点击 go ,它应该打开新的标签/窗口,其中包含根据行数据构建的网址。

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

如何在jquery中执行此操作?我正在做的是:

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
});

一些更新:

我是什么我真正要完成的是动态更新< a> 元素的 href

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>

哪个不起作用(小提琴: http://jsfiddle.net/6eLjA/

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

推荐答案

试试这个:

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)

这篇关于单击jquery中的链接打开新选项卡(窗口)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆