窗口上的Meteor回调.open(url)未打开窗口

Meteor callback on window.open(url) does not open window

本文关键字:url 开窗口 open Meteor 回调 窗口      更新时间:2023-09-26

如果有人知道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){...})的客户端回调中,window.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>

client/client.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
    });
  }
});

server/server.js

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的反弹出过滤器捕获。

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

真的没有太多的方法可以通过这个。您可以在运行回调时创建一个新按钮,然后要求用户单击它以打开一个新窗口。