Javascript 窗口上的Meteor回调。打开(url)不会打开窗口

Javascript 窗口上的Meteor回调。打开(url)不会打开窗口,javascript,url,callback,window,meteor,Javascript,Url,Callback,Window,Meteor,如果有人知道为什么window.open()在Meteor.call()的回调中不起作用,我会很高兴。您可以通过在客户机上调用Meteor.call('method',argument,callback(e,r){…})的回调中调用window.open(url)来轻松地再现这一点。它在回调外部工作,在回调内部,window.location=url正确重定向 我的数据库中有一些来自filepicker.io的安全URL。由于提前生成所有策略和签名效率很低,因此我希望在有人实际尝试检索这些文件时

如果有人知道为什么
window.open()
Meteor.call()的回调中不起作用,我会很高兴。您可以通过在客户机上调用
Meteor.call('method',argument,callback(e,r){…})
的回调中调用
window.open(url)
来轻松地再现这一点。它在回调外部工作,在回调内部,
window.location=url
正确重定向

我的数据库中有一些来自filepicker.io的安全URL。由于提前生成所有策略和签名效率很低,因此我希望在有人实际尝试检索这些文件时,在单击事件中生成它们。不幸的是,在Meteor.call('methodname',param,callback(e,r){…})
的客户端回调中,
窗口.open(url)
似乎不起作用,我不知道为什么

模板

<template name="upload">
  <div class="btn-group btn-group-vertical">
    {{#each files}}
      <button id="fp" class="btn btn-primary">{{filename}}</button>
    {{/each}}
  </div>
</template>
server/server.js

Template.upload.files=function(){
    return files.find({});
}
Template.upload.events({
  'click #fp':function(){
    // window.open(this.url)
    // if I uncomment the above line, a new window
    // opens with the unsigned url
    // (this.url is a valid mongo cursor)
    Meteor.call('signedUrl',this.url,function(err,result){ // result is signed url
      console.log(result); // loggs the correct url in the console
      // window.location = result;
      // if uncommented, the line above redirects correctly 
      window.open(result); // does NOT open the new window with the signed url
    });
  }
});
Meteor.methods({
  signedUrl: function(url) {
    // some proven-to-work-code that you can find at
    // http://stackoverflow.com/questions/18546676
    console.log(signed_url); // loggs the correctly signed url on the server
    return signed_url;
  }
});

提前感谢您的任何提示!致以最诚挚的问候

这很可能被chrome/safari的反弹出过滤器捕捉到

您可能希望以非恶意方式使用新窗口,但现代浏览器需要用户输入才能打开新窗口。在回调中没有用户输入的“触发器”,因此浏览器可能认为它是一个弹出/广告


真的没有什么办法可以通过这个考试。您可以在回调运行时创建一个新按钮,然后让用户单击它以打开一个新窗口。

谢谢您的提示,我也首先想到了弹出窗口拦截器,但这真的是因为在回调外部调用新窗口时不会出现问题的原因吗?是的,因为在回调外部,您将通过某种UI操作(单击、输入等)触发它。为了实现这一点,您使用某种用户输入来触发它。在回调函数中,它是独立的(类似于广告弹出窗口的方式,只要脚本运行,或者在没有任何用户界面触发器的情况下,在一段时间后独立出现)。当回调链接到用户操作时,回调不起作用,因为这可能会被滥用(即加载页面,在计时器中等待回调或其他东西,然后触发弹出窗口-大多数广告都会这样做)是的,谢谢。这完全有道理,不过还是有点悲哀;)