简体   繁体   English

通过script标签包含文本或XML文件?

[英]Include a text or XML file via the script tag?

For a little context I'm working on a site for a client and it has to run completely offline. 在某种程度上,我正在为一个客户端网站工作,它必须完全脱机运行。 It's just a set of html/css/js files that you run locally. 这只是在本地运行的一组html / css / js文件。 The computers it will be used on are office computers and quite locked down so I can't even use java. 它将用于的计算机是办公计算机,并且已被完全锁定,因此我什至不能使用Java。 Luckily the project isn't overly complicated and I've accomplished most of my goals with this limited platform. 幸运的是,该项目并不太复杂,我已经在这个有限的平台上实现了我的大部分目标。 The issue I'm having is I want to create some easy to change files to load the data from. 我遇到的问题是我想创建一些易于更改的文件以从中加载数据。 Right now I have all the data loading through script tags that point to js files that can be manually edited, however I've tried to make the javascript as simple and straight forward as I can but it's still not looking very friendly to someone who hasn't programmed before. 现在,我已经通过脚本标签加载了所有数据,这些脚本标签都指向可以手动编辑的js文件,但是我尝试使javascript尽可能简单明了,但对于那些没有之前没有编程。

What I would like to do is include an xml file or text file in the HTML using a script tag or something similar and then use JS to read the contents but every time I try this it doesn't actually load the file. 我想做的是在HTML中使用脚本标签或类似标签包含一个xml文件或文本文件,然后使用JS读取内容,但是每次尝试这样做实际上都不会加载该文件。 Here's a few things I've tried: 这是我尝试过的一些方法:

<script type="text/xml" src="myxml.xml"></script>
<script type="text/plain" src="myxml.xml"></script>

I've tried using XMLHttpRequest but most of these attempts end in the same result.. can't do a cross-site request. 我已经尝试过使用XMLHttpRequest,但是大多数尝试都以相同的结果结束..无法执行跨站点请求。 Even though I'm using a url "myxml.xml" and they're in the same folder, chrome is still convinced this is a XSS attempt. 即使我使用的是URL“ myxml.xml”,并且它们位于同一文件夹中,chrome仍然确信这是XSS尝试。 So I'm starting to run out of ideas. 所以我开始用尽所有想法。 Can anyone think of any clever way to achieve this? 谁能想到实现这一目标的任何聪明方法?

IF you're goal is to just run your web-app , even offline and you do not care about cross-browser compatibility, you can consider to convert you're application to Packaged App . 如果您的目标是仅运行web-app ,甚至是脱机运行,并且您不关心跨浏览器的兼容性,则可以考虑将您的应用程序转换为Packaged App

It will work only in google-chrome browser but setting the right permissions, you should not have problem with cross-site requests. 它仅在google-chrome浏览器中有效,但设置了正确的权限,跨站点请求应该没有问题。 At this point, you could download the xml content through a noraml XMLHttpRequest . 此时,您可以通过noraml XMLHttpRequest下载xml内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM