在一个工作站中模拟同源策略

时间:2011-03-23 20:01:10

标签: javascript same-origin-policy

我正在尝试使用自己的笔记本电脑模拟相同的原始政策用于研究目的。 我尝试了以下方式,但它不起作用:

的httpd.conf:

...
    NameVirtualHost *:80

    <VirtualHost *:80>
      ServerName www.client.es
      DocumentRoot "C:/maestro/desarrollo/Apache Software Foundation/Apache2.2/htdocs/client"
      <Directory "C:/maestro/desarrollo/Apache Software Foundation/Apache2.2/htdocs/client">
        AllowOverride All
        Allow from All
      </Directory>
    </VirtualHost>  

    <VirtualHost *:80>
      ServerName www.custom.es
      DocumentRoot "C:/maestro/desarrollo/Apache Software Foundation/Apache2.2/htdocs/custom"
      <Directory "C:/maestro/desarrollo/Apache Software Foundation/Apache2.2/htdocs/custom">
        AllowOverride All
        Allow from All
      </Directory>
    </VirtualHost>  
...

现在,为了获得SOP效果,我构建了两个不同的模拟站点:

www.client.es/index.htm

...
<html>
...
<script type="text/javascript" src="http://www.custom.es/js/hello.js"></script>
...
</body>
</html>

www.custom.es/js/hello.js

alert("Hello.js: loaded");

最后,我在etc / hosts

中添加了正确的行
127.0.0.1   www.custom.es
127.0.0.1   www.client.es

所以我可以从浏览器中获得不同的模仿,就好像它们是真正不同的网站一样。

问题是我期待Chrome / Firefox /资源管理器/等无法获取hello.js由于同源策略但是所有内容都已提供,并且当我没有错误时浏览www.client.es/index.htm

有任何线索吗?提前谢谢。

1 个答案:

答案 0 :(得分:3)

对于从其他域的<script>标记中下载和执行javascript没有任何限制。这些限制是针对跨域ajax的。你做了什么会很好。