如何使用 javascript 完全复制中键点击行为
我的网站上有一个表格,其标签上有点击事件,因此它们的作用类似于链接。我正在尝试正确复制中间单击事件,以便它的行为与普通链接相同。
当我单击鼠标中键时,它会打开一个新选项卡,但我想让新选项卡弹出而不是弹出(即不获取焦点)。
有办法做到这一点吗?
这是我目前正在工作的一些示例代码
<script type="text/javascript">
urlTemplate = '/library/edit/ID';
$(document).ready(function() {
$('.row_link').mousedown(function(e){
e.preventDefault();
e.stopPropagation();
});
$('.row_link').mouseup(function(e){
url = urlTemplate.replace('ID',$(this).attr('rel'));
if(e.which === 1) {
e.preventDefault();
e.stopPropagation();
document.location.href=url;
}
else if(e.which === 2) {
e.preventDefault();
e.stopPropagation();
window.open(url);
}
});
});
</script>
...
<table id="document-index">
<tr class="row_link" rel="4004">
<td>IBTAKTF.pdf</td>
<td>blah, blah, blah</td>
</tr>
</table>
I have a table on my site that has click events on it's tags, so they act like links. I'm trying to properly duplicate the middle click event so it acts the same way as normal links.
I have it opening up a new tab when I middle click, but I want to get the new tab to pop under rather than pop up (ie not take focus).
Is there a way to do this?
Here's some sample code ofr what I have working at the moment
<script type="text/javascript">
urlTemplate = '/library/edit/ID';
$(document).ready(function() {
$('.row_link').mousedown(function(e){
e.preventDefault();
e.stopPropagation();
});
$('.row_link').mouseup(function(e){
url = urlTemplate.replace('ID',$(this).attr('rel'));
if(e.which === 1) {
e.preventDefault();
e.stopPropagation();
document.location.href=url;
}
else if(e.which === 2) {
e.preventDefault();
e.stopPropagation();
window.open(url);
}
});
});
</script>
...
<table id="document-index">
<tr class="row_link" rel="4004">
<td>IBTAKTF.pdf</td>
<td>blah, blah, blah</td>
</tr>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
http://www.w3schools.com/jsref/met_win_focus.asp
try
http://www.w3schools.com/jsref/met_win_focus.asp