Javascript document.domain
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6898253/
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
Javascript document.domain
提问by Darren Young
I'm trying to access a work server for use with an application called Spotfire. My colleague who passed me this is now off for a couple of weeks, and I have an issue with what he advised me.
我正在尝试访问工作服务器以与名为 Spotfire 的应用程序一起使用。我的同事给我传了这个消息,现在已经休息了几个星期,我对他的建议有疑问。
Effectively when I run my web app via localhost, I get an error saying that I cannot access my work server. My colleague had said that I need to set document.domain to our work domain, but when I do this as such:
实际上,当我通过 localhost 运行我的 Web 应用程序时,我收到一条错误消息,指出我无法访问我的工作服务器。我的同事说我需要将 document.domain 设置为我们的工作域,但是当我这样做时:
document.domain = "workdomain.net";
I get an error saying that it is an invalid argument. Any idea how to get around this?
我收到一个错误,说这是一个无效的参数。知道如何解决这个问题吗?
Thanks,
谢谢,
Darren.
达伦。
回答by Ash Eldritch
From https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript
来自https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript
"A script can set the value of document.domain to a subsetof the currentdomain. If it does so, the shorter domain is used for subsequent origin checks."
“脚本可以设置document.domain的一个的值的子集的的当前域。如果是这样,则较短的域用于后续原点检查”。
The reason you're getting the javascript error is because you're trying to set the document.domain to a completely different domain than your current one ("localhost").
您收到 javascript 错误的原因是您试图将 document.domain 设置为与当前域(“localhost”)完全不同的域。
Rather than this, I suggest you add an entry to your host file...
而不是这个,我建议你在你的主机文件中添加一个条目......
127.0.0.1 local.workdomain.net
...and then navigate to local.workdomain.net
...然后导航到 local.workdomain.net