我试图在此处的示例之后对我的代码进行建模:http ://connect.soundcloud.com/examples/connecting.html#
它适用于Firefox,但不适用于chrome。在 chrome 中,soundcloud 弹出窗口正确显示,我可以登录(返回 sc-connect.html),但随后窗口不会关闭。经过仔细检查,由于 window.opener 为空,因此存在 javascript 错误。我想知道它是否与localhost uri有关?上面链接中的示例适用于 firefox 和 chrome。有任何想法吗?我的代码如下:
SC.initialize({client_id:'my_client_id', redirect_uri:'http://localhost:3000/sc-connect.html'});
$('button').click(function(){
SC.connect(function () {
console.log('made it');
}
}
我的 sc-connect.html 页面如下所示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Connect with SoundCloud</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body onload="window.opener.setTimeout(window.opener.SC.connectCallback, 1)">
<b style="width: 100%; text-align: center;">This popup should automatically close in a few seconds</b>
</body>
</html>
此应用程序在 soundcloud 上的重定向 URI:http://localhost:3000/sc-connect.html