代码之家  ›  专栏  ›  技术社区  ›  Hriday Modi Victor Manuel

如何确定我的域已打开弹出窗口?

  •  -1
  • Hriday Modi Victor Manuel  · 技术社区  · 8 年前

    所以有一个类似的网址:

    https://subdomain.domain.com/popuppage

    我在弹出窗口中打开此项,使用:

    window.open("https://subdomain.domain.com/popuppage", null, "height=600,width=800")

    现在,单击第三方网站链接后,在新选项卡中打开相同的页面。问题是我想确定它是由我或第三方网站打开的。有什么办法吗?

    我试过查一下 window.opener 但在这两种情况下我都得到 开窗器 浏览器不允许我访问 开窗器 因为CORS政策。

    1 回复  |  直到 8 年前
        1
  •  0
  •   Lain    8 年前

    window.opener.location.href

      window.onload = function(){
        var _CORS = null;
    
        try{
          window.opener && window.opener.location.href;
          _CORS = false
          //REM: Edit according to comment
          /*
          _CORS = !(
              !window.opener ||
              (window.opener.location.href && window.location.host === window.opener.location.host)
          )
          */
        }
        catch(err){
          _CORS = true
        };
    
        alert('Third party: ' + _CORS)
      };

    https://subdomain.domain.com/popuppage <head>

    推荐文章