SoundCloud: callback.html popup doesn't close

坚强是说给别人听的谎言 提交于 2019-12-06 05:53:10

SoundCloud's sample code is broken.

This is from SoundCloud's callback.html

<body onload="window.opener.setTimeout(window.opener.SC.connectCallback, 1)">

This is how I got it to work:

<body onload="window.setTimeout(window.opener.SC.connectCallback, 1)">

SoundCloud's connectCallback uses this.location to collect the OAuth access token. If you set the timeout on window.opener, inside connectCallback this will refer to your app's window and the location will be your main page. Whereas setting it on window will bind this to the callback popup window, and this.location will contain the access token in the query arguments.

I also faced the same issue, and found the solution, if you change your callback.html to below two options, it will work -

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Connect with SoundCloud</title>
  </head>
  <body onload="window.opener.setTimeout(window.opener.SC.connectCallback, 1)">
    <b style="text-align: center;">This popup should automatically close in a few seconds</b>
    <script type="text/javascript">
        window.opener.SC.connectCallback.call(this);
    </script>
  </body>
</html>

Or

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Connect with SoundCloud</title>
  </head>
  <body onload="setTimeout(window.opener.SC.connectCallback)">
    <b style="text-align: center;">This popup should automatically close in a few seconds</b>
  </body>
</html>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!