jQuery的getScript和本地文件系统 - 限制/替代? [英] jQuery's getScript and the local file system-- limitations/alternatives?

查看:73
本文介绍了jQuery的getScript和本地文件系统 - 限制/替代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在开发一个基于本地文件系统的帮助系统。它的目的是附带一个不在支持互联网的机器上使用的产品,因此它必须是一个独立的网页,不依赖于Web服务器。

Right now I'm working on a help-system which is based on a local file system. It is intended to be shipped with a product which is not used on internet-enabled machines, so it must be a stand alone webpage, without any dependencies on a web server.

这引入了一些挑战。也就是说,文件所在的目录结构需要向上和向上导航以访问显示帮助系统所需的某些.js文件。这个用法是使用jQuery getScript函数实现的,但我在本地文件系统上遇到了一些问题。

This introduces a few challenges. Namely, the directory structure that the files exist in require navigating "up and over" to access some .js files which are required to display the help system. This use to be implemented using the jQuery getScript function, but I have ran into some problems using this on the local file system.

乍一看,似乎如果我的话网页是在C:/ dev / webpage / html /目录下提供的,我需要的文件在C:/ dev / webpage / js /(topic)/file.js中,我可以构建一个绝对路径( file:/// ...)并将其传递给getScript函数。

At first glance, it seemed that if my webpage was being served out of the C:/dev/webpage/html/ directory, and the files I needed were in C:/dev/webpage/js/(topic)/file.js, I could just build an absolute path (file:///...) and pass that into the getScript function.

然而,在测试之后,getScript函数似乎不会让我走从html目录中找到一个级别(html文件所在的位置,其中包含网页的主要代码)。不幸的是,我无法更改目录结构,也无法更改.js文件结构/格式。

However, after testing this, it does not seem that the getScript function will let me go up a level from the html directory (where the html file is located which has the main code for the webpage). Unfortunately, I can not change the directory structure, nor can I change the .js file structure/format.

是否有替代方法可以加载/执行javascript文件我需要翻转的文件结构?

Is there an alternative for loading/executing javascript files that are in a file structure where I need to go "up and over"?

谢谢,

编辑 - 我做了看看这个类似于我的问题,但在我的情况下,将数据更改为JSON格式的建议不是一个选项:在本地文件上使用Javascript / jQuery拒绝权限

Edit- I did look at this question that resembled mine, but the recommendation of changing data to a JSON format was not an option in my case: Permission Denied using Javascript/jQuery on a local file

推荐答案

并不是说它不会让你升级......在某些情况下也是如此,那就是你可能正在击中同源政策,以确保安全。以下是您的一些解决方案/选项。

It's not that it won't let you go up a level...which is also true in some cases, it's that you're probably hitting the same-origin policy in place for security. Here's a few solutions/options you have.

您最好的长期选择是在盒子上设置Web服务器,编辑/保存文件,但通过 http:// localhost url查看它。如果您正在进行大量的HTML / CSS / JS工作,这将是获得您想要的最简单方法。

Your best long-term option for this is to setup a web server on the box, edit/save the file as you have it, but view it through a http://localhost url. This is going to be the easiest way to get what you want if you're doing a lot of HTML/CSS/JS work down the road.

或者,您可以在chrome(可能是其他浏览器)中加载页面并禁用该策略,这样您就可以完成一些工作(创建不同的快捷方式)用于开发,而非一般用途!)。

Alternatively, you could load you page in chrome (maybe other browsers) and disable that policy so you can get some work done (create a different shortcut for development, not general use!).

对于 Chrome 通过编辑快捷方式并将 - disable-web-security 添加到命令行来禁用它,例如:

For Chrome you disable it by editing the shortcut and adding --disable-web-security to your command line, for example:

C:\Users\USERHERE\AppData\Local\Google\Chrome\Application\chrome.exe --disable-web-security

这篇关于jQuery的getScript和本地文件系统 - 限制/替代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆