gpt4 book ai didi

javascript - 创建 FollowMe 链接 SoundCloud

转载 作者:行者123 更新时间:2023-12-03 01:04:47 25 4
gpt4 key购买 nike

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

最佳答案

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

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

关于javascript - 创建 FollowMe 链接 SoundCloud,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12575075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com