JQuery getScript and local file system - limitations / alternatives?

I am currently working on a help system based on the local file system. It is intended to ship with a product that is not used on computers that support the Internet, so it should be a stand-alone web page without any dependencies on the web server.

This creates several problems. Namely, the directory structure in which the files exist requires up and down navigation to access some of the .js files that are needed to display the help system. This usage should be implemented using the jQuery getScript function, but I ran into some problems using this on the local file system.

At first glance, it seemed that if my web page was submitted from 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 this to the getScript function.

However, after testing this, it does not seem that the getScript function will allow me to go to the level from the html directory (where the html file with the main code for the web page is located). Unfortunately, I cannot change the directory structure, nor can I change the structure / format of the .js file.

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

Thanks,

Change I looked at this question similar to mine, but the recommendation to change the data in JSON format was not an option in my case: Permission denied using Javascript / jQuery local file

+4
source share
2 answers

It’s not that it will not allow you to rise to the level ... which is also true in some cases, it is that you are probably pushing policies of the same origin to ensure security. Here are some solutions / options that you have.

Option 1

Your best long-term option for this is to set the web server in the field, edit / save the file as you like, but view it using http://localhost url. This will be the easiest way to get what you want if you do a lot of HTML / CSS / JS work along the way.

Option 2

Alternatively, you can load the page in chrome (possibly in other browsers) and disable this policy so that you can do a certain job (create another shortcut for development, and not for general use!).

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 
+6
source

Why not just build a relative path? An absolute path is a bad idea, as you cannot be 100% sure of the installation path. (Some clients may install on D: for example.)

If the page is "file: //something/html/thepage.html", does "../js/ script.js" work?

-1
source

Source: https://habr.com/ru/post/1310573/


All Articles