【问题标题】:Creating FollowMe link SoundCloud创建 FollowMe 链接 SoundCloud
【发布时间】:2012-09-16 12:08:10
【问题描述】:

我正在尝试为我们的公司创建一个简单的 FollowMe 链接,但我遇到了用户不允许弹出窗口的问题。代码如下:

$(document).ready(function(){
  SC.initialize({
    client_id: '***********************',
    redirect_uri: 'http://localhost:8002/callback.html'
  });
  var isCalled = false;
  var connect = function (){
    isCalled = true;
    SC.connect(function(){
      SC.put('/me/followings/123456', function(me, error){
        console.log('me: ', me)
        console.log('error: ', error)
        window.location.replace("http://www.soundcloud.com");
      });
    });
  };
  $('a').click(function(){
    isCalled = true;
    connect();
  });
  if(!isCalled){
    console.log(isCalled);
    //console.log('connect called')
    isCalled = true;
    connect();
  }
});

目前,如果您在浏览器中允许弹出窗口,则您可以正确关注所需的用户,但是当用户阻止弹出窗口并单击链接时,他们会在对话框中收到以下错误。

Unsafe JavaScript attempt to access frame with URL http://localhost:8002/ from frame with URL http://soundcloud.monstercat.com/callback.html?code=79e58c1c4ee8b3fb2a1c935fb676da90&state=SoundCloud_Dialog_1c798#access_token=1-24501-24540735-ab27bed0d285f42&scope=non-expiring. Domains, protocols and ports must match. callback.html:6

Uncaught TypeError: Cannot read property 'connectCallback' of undefined callback.html:6

Unsafe JavaScript attempt to access frame with URL http://soundcloud.monstercat.com/callback.html?code=79e58c1c4ee8b3fb2a1c935fb676da90&state=SoundCloud_Dialog_1c798#access_token=1-24201-27645735-ab27bed0d285f42&scope=non-expiring from frame with URL http://soundcloud.monstercat.com/callback.html?code=79e58c1c4ee8b3fb2a1c935fb676da90&state=SoundCloud_Dialog_1c798#access_token=1-24201-27645735-ab27bed0d285f42&scope=non-expiring. Domains, protocols and ports must match.

任何帮助将不胜感激。

注意:callback.html 是 soundcloud 开发网站的标准文件。

【问题讨论】:

    标签: javascript api oauth-2.0 soundcloud


    【解决方案1】:

    您在页面加载后立即致电connect(因此尝试关注您自己)。这就是弹出窗口被阻止的原因。除非在处理点击事件时弹出立即发生,否则浏览器将阻止它。从该脚本的末尾删除这部分:

      if(!isCalled){
        console.log(isCalled);
        //console.log('connect called')
        isCalled = true;
        connect();
      }
    

    【讨论】:

      猜你喜欢
      • 2013-12-24
      • 1970-01-01
      • 2015-06-09
      • 2015-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-01
      • 2018-11-04
      相关资源
      最近更新 更多