3

我正在尝试为我们的公司创建一个简单的 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 开发站点的标准文件。

4

1 回答 1

0

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

  if(!isCalled){
    console.log(isCalled);
    //console.log('connect called')
    isCalled = true;
    connect();
  }
于 2012-12-01T12:37:59.267 回答