我的 dojo 仅在通过 HTTP 访问时有效
我下载了 dojo 工具包并打开 dijit/themes/themeTester.html。道场不能工作。我必须将该工具包复制到我的 Web 服务器的 webapp 目录中。然后我通过 HTTP 访问相同的 html。道场工作了。
在开发过程中,我是否必须始终将页面部署到Web服务器进行测试?
谢谢。
I downloaded the dojo toolkit and open the dijit/themes/themeTester.html. The dojo can't work. I have to copy the toolkit to the webapp directory of my web server. Then I access the same html through HTTP. The dojo works.
During the development, do I have to always deploy a page to web server for testing?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此行为不是 Dojo 特有的。出于安全原因,某些浏览器(例如 Firefox)禁止直接从文件系统加载的网页加载其主目录之外的资源。
示例:您的网页位于
/home/bob/page.html
中。它可以包含以下资源:bob.js
(有效路径:/home/bob/bob.js
)./sam.js
(<代码>/home/bob/sam.js)abc/spot.js
(/home/bob/abc/spot.js
) 无法加载以下资源(即使存在):
../bob.js
(/home/bob.js
)/home/tom/script.js
../tom/script.js
(/home/tom/script.js
)理论上你可以进入 Firefox 内部并关闭这个“功能” ,但您可能会遇到其他问题:
除此之外,您应该能够直接从文件系统运行任何 Web 应用程序。只需确保整个应用程序位于一个文件夹中,所有 HTML 页面都位于顶部文件夹中(或子文件夹中,但不要使用它们“上方”的任何内容),避免绝对路径和“向上”符号 (
..
)位于将您带出主文件夹(即使是暂时的)的路径中,并始终测试您的 XHR 响应。This behavior is not Dojo-specific. Some browsers (Firefox comes to mind) prohibit web pages loaded directly from file system to load resources outside of their home directory for security reasons.
Example: your web page is in
/home/bob/page.html
. It can include following resources:bob.js
(effective path:/home/bob/bob.js
)./sam.js
(/home/bob/sam.js
)abc/spot.js
(/home/bob/abc/spot.js
)It cannot load following resources (even if they exist):
../bob.js
(/home/bob.js
)/home/tom/script.js
../tom/script.js
(/home/tom/script.js
)Theoretically you can go into Firefox guts and turn this "feature" off, but you may encounter other problems:
Other than that you should be able to run any web application directly from file system. Just make sure that the whole app is inside one folder, all HTML pages are in the top folder (or in subfolders, but do not use anything "above" them), avoid absolute paths, and "go up" symbols (
..
) in paths that take you outside of the main folder (even temporarily), and always test your XHR responses.