3

当社の簡単なフォローミー リンクを作成しようとしていますが、ユーザーがポップアップを許可していない場合に問題が発生しています。コードは次のとおりです。

$(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 に答える