Cross-domain JavaScript code with sibling sub-domains

后端 未结 2 1879
既然无缘
既然无缘 2021-01-06 00:22

I have two web applications setups:

david.example.com and john.example.com

David opens a new window to John:



        
2条回答
  •  长发绾君心
    2021-01-06 01:05

    You should be able to do this, as long as you set document.domain on both DOM's.

    document.domain = location.host.replace(/^.*?([^.]+\.[^.]+)$/g,'$1');
    

    Credited to Martin Jespersen

提交回复
热议问题