1

All I want to get address bar URL, tried with this javascript, but shows as location{} (empty value)

var googleWindow = window.open('https://api.something/givetokenafterclosed');

var waitForToken = setInterval(function () {
    console.log(googleWindow.location)
    if (googleWindow.closed) {
        clearInterval(waitForToken);
    }
    if (window.location.hash) {
        // here I'm retrieving some token...
        googleWindow.close();
    }
}, 3000); // time interval set to 3 secs

If I open localhost urls It works fine. Help me to get opened window URL in above case.

4

1 回答 1

3

当窗口加载另一个来源的文档时,URL 可能包含机密信息,因此浏览器不会让您的 JS 访问它。

如果您想从另一个域获取令牌,则另一个域需要重定向回您的域并传递令牌。

于 2013-04-29T14:58:18.043 回答