javascript 同源主机,JS 中不同的端口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5714135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 18:05:59  来源:igfitidea点击:

Same origin host, different ports in JS

javascriptdomsame-origin-policy

提问by F.P

for the two hosts

对于两位主持人

http://1.com.local/
http://2.com.local:8080/

how can I use document.domainto enable DOM-Manipulation between the two? If i set both to com.localit doesn't work, because the 2nd host then gets the domain com.local:8080.

如何document.domain在两者之间启用 DOM-Manipulation?如果我将两者都设置为com.local它不起作用,因为第二个主机然后获取域com.local:8080

When I try to set the domain of the first one to com.local:8080manually, the port is just snipped of and the domain remains com.local.

当我尝试com.local:8080手动将第一个域设置为com.local.

How can I enable DOM-Manipulation in this situation?

在这种情况下如何启用 DOM 操作?

回答by mplungjan

You cannot. Sorry - same origin is including the ports

你不能。对不起 - 同源包括端口

You can use CORSand ajax to copy some stuff from one server to the other if you enable this.

如果启用此功能,您可以使用CORS和 ajax 将一些内容从一台服务器复制到另一台服务器。