Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript/TypeScript在弹出窗口中打开网站,并在成功登录时关闭_Javascript_Typescript - Fatal编程技术网

使用Javascript/TypeScript在弹出窗口中打开网站,并在成功登录时关闭

使用Javascript/TypeScript在弹出窗口中打开网站,并在成功登录时关闭,javascript,typescript,Javascript,Typescript,我正在尝试从网站B到网站A获取数据。这需要我手动登录到网站B。 我试图做的是从a打开一个B的弹出窗口,登录到B并自动关闭包含B的弹出窗口 问题是B和A是跨域的,Javascript具有安全特性,阻止我使用获取网站B的当前URL、检测网站B的URL变化的功能 有什么解决办法吗 我的代码如下: private websiteBRedirect(){ let popupWindow = window.open("websiteB", 'popup','height=' + 600 + ',

我正在尝试从网站B到网站A获取数据。这需要我手动登录到网站B。 我试图做的是从a打开一个B的弹出窗口,登录到B并自动关闭包含B的弹出窗口

问题是B和A是跨域的,Javascript具有安全特性,阻止我使用获取网站B的当前URL、检测网站B的URL变化的功能

有什么解决办法吗

我的代码如下:

  private websiteBRedirect(){
    let popupWindow = window.open("websiteB", 'popup','height=' + 600 + ',width=' + 600 + ',resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes');
    let timer = setInterval(checkChild, 500);
    let url = this.authUrl[0];

    function checkChild() {
      if (popupWindow.closed) {
          window.location.href = url;
          clearInterval(timer);
      }
    }
  }
在这里,我创建了一个名为“popupWindow”的弹出变量,它加载websiteB的登录页面(使用websiteB而不是实际的机密网站)。 我想检查用户是否已成功登录网站B,然后关闭弹出窗口。
关闭弹出窗口后,如果登录成功,我的代码会将我的当前URL(websiteA)更改为另一个URL,不幸的是,我无法对其进行测试。

您可以使用JSONP进行跨域请求

JSONP只是指“带填充的JSON”。它本质上是一个围绕URL中指定的回调函数的JSON响应。例如,下面的代码是一个JSON响应

{ “username”: “sdaityari”, “name”: “Shaumik Daityari”}
将回调函数指定为processData的相同响应如下所示

processData({ “username”: “sdaityari”, “name”: “Shaumik Daityari”})
这将帮助您找到解决问题的方法,因为您没有发布任何我可以使用的代码