Ginew.Z 的博客

          一切,為了讓生活更簡(jiǎn)單、更自然

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            21 Posts :: 0 Stories :: 14 Comments :: 0 Trackbacks

          以前如果要使iframe里面的腳本能訪問(wèn)parent的內(nèi)容,但iframe和parent的二級(jí)域名相同,那一般都會(huì)在兩者都寫(xiě)上document.domain="xxx.com" 以放寬訪問(wèn)權(quán)限。

          今天發(fā)現(xiàn),如果iframe和parent在同一個(gè)三級(jí)域名下,比如都是aa.bb.com,那設(shè)了document.domain反而會(huì)造成訪問(wèn)拒絕。

          查了下MSDN,有如下解釋?zhuān)?br />

          Remarks

          The property initially returns the host name of the server from which the page is served. The property can be assigned the domain suffix to allow sharing of pages across frames. For example, a page in one frame from home.microsoft.com and a page from www.microsoft.com initially would not be able to communicate with each other. However, by setting the domain property of both pages to the suffix "microsoft.com", you ensure that both pages are considered secure and access is available between the pages.

          When you set the domain property, use the domain name determined by the server rather than by the client browser.

          All the pages on different hosts must have the domain property explicitly set to the same value to communicate successfully with each other. For example, the value of the domain property of a page on the host microsoft.com would be "microsoft.com" by default. It might seem logical that if you set the domain property of a page on another host named msdn.microsoft.com to "microsoft.com," that the two pages could communicate with each other. However, this is not the case unless you have also explicitly set the domain property of the page on microsoft.com to "microsoft.com".

          Furthermore, this property cannot be used to allow cross-frame communication among frames with different domain suffixes. For example, a page in one frame from www.microsoft.com and a page in another frame from www.msn.com would not be able to communicate with each other even if the domain property of both pages was set to the suffix "microsoft.com".

          security note Security Alert??Using this property incorrectly can compromise the security of your Web site. Set the domain property only if you must allow cross-domain scripting. Use a value determined on the server. Setting this property to a value determined on the client (like through the location object) could expose your site to attack from another site through Domain Name System (DNS) manipulation. For more information, see Security Considerations: Dynamic HTML.

          For more information on domain security, see About Cross-Frame Scripting and Security.

          posted on 2006-04-13 11:54 無(wú)風(fēng)之雨 閱讀(9359) 評(píng)論(3)  編輯  收藏 所屬分類(lèi): JavaScript

          Feedback

          # re: document.domain與域名的問(wèn)題 2012-07-26 13:48 問(wèn)學(xué)堂
          嗯,學(xué)習(xí)了,謝謝!  回復(fù)  更多評(píng)論
            

          # re: document.domain與域名的問(wèn)題 2012-07-29 18:02 jdwx
          document.domain跨域問(wèn)題,學(xué)習(xí)了,謝謝。  回復(fù)  更多評(píng)論
            

          # re: document.domain與域名的問(wèn)題 2013-05-31 08:03 lsb
          好值得學(xué)習(xí)  回復(fù)  更多評(píng)論
            

          主站蜘蛛池模板: 新田县| 延安市| 阳朔县| 江达县| 横山县| 濮阳市| 成武县| 云和县| 永仁县| 洪洞县| 淮南市| 诸暨市| 鱼台县| 纳雍县| 大足县| 宾川县| 延川县| 丰都县| 庆云县| 潮安县| 南阳市| 九江县| 沧州市| 三江| 临泽县| 兴义市| 桐庐县| 盖州市| 札达县| 连州市| 正定县| 陆川县| 阿拉尔市| 方正县| 湖南省| 伊宁市| 张家港市| 兰考县| 德令哈市| 余江县| 铅山县|