代码之家  ›  专栏  ›  技术社区  ›  MistyD Harish Kumar Kailas

将自定义内部URL传递给window.open而不指定域名

  •  0
  • MistyD Harish Kumar Kailas  · 技术社区  · 6 年前

    我正在做这个

      __CHILD_WINDOW_HANDLE = window.open('http://localhost:59304/pageB', '_blank', 'width=700,height=500,left=200,top=100');
    

    但是我不想硬编码 http://localhost:59304/ 在我的 window.open 有没有办法在运行时得到这个部分?

    1 回复  |  直到 6 年前
        1
  •  1
  •   fiveelements    6 年前

    正如我在原始文章的注释中提到的,如果指定相对路径,它将自动采取 protocol, host, and port 从地址栏( window.location )并使绝对URL:

    window.open('/pageB', '_blank', 'width=700,height=500,left=200,top=100');