gpt4 book ai didi

javascript - 在一台工作站中模拟同源策略

转载 作者:行者123 更新时间:2023-11-28 21:24:27 25 4
gpt4 key购买 nike

出于研究目的,我正在尝试使用自己的笔记本电脑模拟同源策略。我尝试了以下方法,但它不起作用:

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/Explorer/etc 无法获取 hello.js,但一切都已提供,并且当我浏览至 www.client.es/index.htm

有什么线索吗?提前致谢。

最佳答案

<script>中对下载和执行javascript没有任何限制来自不同域的标签。这些限制是针对跨域 ajax 的。你所做的一切都会很好。

关于javascript - 在一台工作站中模拟同源策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5410926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com