document.domain = document.domain做什么? [英] What does document.domain = document.domain do?

查看:145
本文介绍了document.domain = document.domain做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Orbited (Comet服务器)的客户端JS组件要求如果服务器正在运行JS本身的不同域或端口,必须执行

The client-side JS component of Orbited (a Comet server), requires that if the server is running on a different domain or port to the JS itself, you must execute

document.domain = document.domain;

。 (请参阅文档。)

什么这个吗?它看起来像一个NOOP! (我已经检查了,实际上是必要的。)

What does this do? It looks like a NOOP! (I've checked and it is in fact necessary.)

推荐答案

我实际上是在写这段代码。

I actually wrote this code.

当尝试执行跨子域/端口彗星时,iframe需要具有相同的 document.domain 值作为父帧。不幸的是,浏览器在内部存储了原始 document.domain 值的域名和端口。但是javascript中的getter和setter对端口一无所知。所以问题是:如果顶部框架 document.domain ('example.com',80),底部框架是('comet.example.com',80),如何让底部框架为('example.com ',80)以及?

When trying to do cross-subdomain/port comet, the iframe needs to have the same document.domain value as the parent frame. Unfortunately, the browser stores the domain name AND port internally for the original document.domain value. But the getter and setter in javascript knows nothing about the port. So the problem is this: if the top frame document.domain is ('example.com', 80), and the bottom frame is ('comet.example.com', 80), how do you get the bottom frame to be ('example.com', 80) as well?

您不能,因为更改主机名部分必然会导致端口设置为 null ,所以你可以做的最好的是底部框架中的('example.com',null)。因此顶部框架也需要设置为该值,设置 document.domain = document.domain 就是这样做的。它将浏览器中的内部表示从('example.com',80)更改为('example.com',null)然后一切都匹配,跨端口/子域框架通信工作。

You can't, as changing the hostname portion will necessarily cause the port to be set to null, so the best you can do is ('example.com', null) in the bottom frame. So the top frame also needs to be set to that value, and setting document.domain=document.domain does just that. It changes the internal representation in the browser from ('example.com', 80) to ('example.com', null) and then everything matches up and cross-port/subdomain frame communication works.

这篇关于document.domain = document.domain做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆