开发者

Include a text or XML file via the script tag?

开发者 https://www.devze.com 2023-04-07 22:19 出处:网络
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. The computers it will be used on are office c

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. The computers it will be used on are office computers and quite locked down so I can't even use 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.

What I would like to do is include an xml file or text file in the HTML using a script tag or something si开发者_开发技巧milar and then use JS to read the contents but every time I try this it doesn't actually load the file. 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. 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. 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.

It will work only in google-chrome browser but setting the right permissions, you should not have problem with cross-site requests. At this point, you could download the xml content through a noraml XMLHttpRequest.

0

精彩评论

暂无评论...
验证码 换一张
取 消