Hyperlink 在Meteor中用户单击时将事件添加到数据库
当用户点击某个链接时,我试图更新Meteor中的一个集合。该链接将打开一个新选项卡,该选项卡位于外部站点上。但是,我想将此单击存储在我的数据库中Hyperlink 在Meteor中用户单击时将事件添加到数据库,hyperlink,meteor,Hyperlink,Meteor,当用户点击某个链接时,我试图更新Meteor中的一个集合。该链接将打开一个新选项卡,该选项卡位于外部站点上。但是,我想将此单击存储在我的数据库中 我已经尝试使用e.preventDefault(),但是我无法在新选项卡中打开该链接。有什么建议吗?您可以使用单击事件,并在插入数据库后使用窗口。位置。 所以,它看起来像这样: Template.name.events({ 'click a' : function(e) { e.preventDefault(); // Insert
我已经尝试使用e.preventDefault(),但是我无法在新选项卡中打开该链接。有什么建议吗?您可以使用单击事件,并在插入数据库后使用
窗口。位置
。
所以,它看起来像这样:
Template.name.events({
'click a' : function(e) {
e.preventDefault();
// Insert data into database
Table.insert({
// data here
});
// Open new tab
window.open(url, '_blank');
}
});
您可以在安全的服务器端进行插入。该窗口可以在响应成功时打开 客户
Template.name.events{(
"click .clickevent":function(e){
e.preventDefault();
Meteor.call("Methodname", datatoinsert,function(err){
if(!err)
window.open(url, '_blank');
})
}
)};
服务器中
Meteor.methods({
Methodname:function(datatoinsert){
Tablename.insert({
//insert data here
})
}
});
通过这种方式,您可以添加事件,并在成功插入数据时打开一个窗口
我希望它能帮助您。您不应该使用javascript打开新选项卡,因为这将激活弹出窗口阻止程序。最好的解决方案是像正常情况一样使用链接,并在侧面跟踪链接: Html:
这是可行的,但是window.open会导致chrome弹出阻止程序出现。有没有办法解决这个问题?它在Safari中也不起作用。我读到另一个问题,window.open在跨浏览器时无法正常工作。有没有办法在用户离开页面后插入数据,作为某种同步的后台工作。
<template name="link">
<a href="http://google.com" target="_blank" id="the_link">CLick</a>
</template>
Template.link.events({
'click a#the_link': function(e,tmpl) {
MyCollection.update({_id: "the_link_id"} , {$inc { "clicks":1 } });
}
});