Javascript accessing a local file on computer - javascript

is there a way to allow a domain access a file which is stored on my computer?
I wish to inject javascript a tag into a website, with the source as a file stored on my computer. This works within a local test.html page, but not when trying to run the script on an actual domain.
Is there a way to set this up my changing window's host file?
Edit - it MUST work in IE
Clarification :: I wish to use javascript injection (using the javascript: protocol) to manipulate the DOM within IE, this is fine. There is however an 8k byte limit within the address bar, which isn't enough. Therefore I wish to store it within a local file on my computer.

Instead of storing it on your computer you could store it online and then load the Javascript through a much smaller amount of code in the address bar.
It's explained how to do this here
http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml

Try the file API if you're on a recent browser. https://developer.mozilla.org/en/using_files_from_web_applications
If not and you're on IE, you should be able to do it with ActiveX but it'll always ask for permission.

Related

Strange behaviour of onAuthStateChanged() when persistence is set to local [duplicate]

I am creating 2 HTML files that will be stored an an iPhone locally and accessed through a WebView.
I am wondering if it is possible to set localStorage in one file, and get the results of the storage from the other file.
I know that localStorage is accessible from files on the same domain, however, it appears that you can not get the value from a different local file?
I have also tried running this in Safari on the desktop with local files and the same issue occurs.
When you are opening the files locally, i.e. using the file:// protocol, as of now the browsers can not determine what is "same domain" so every file is considered a separate domain. Thus you can not use localStorage when you're opening the files.
Here is some more information on the problem in FireFox: https://bugzilla.mozilla.org/show_bug.cgi?id=507361 . Personally I couldn't find much about Safari on this topic.
You can also look over this: Javascript/HTML Storage Options Under File Protocol (file://) . It might be helpful in your situation.
At this time, local files rendered via WKWebView on iOS 10 share access to the "same domain" with respect to localStorage. Unclear whether this is by design or a bug, however.

LOCALSTORAGE not working offline. Works fine on a live-server [duplicate]

I am creating 2 HTML files that will be stored an an iPhone locally and accessed through a WebView.
I am wondering if it is possible to set localStorage in one file, and get the results of the storage from the other file.
I know that localStorage is accessible from files on the same domain, however, it appears that you can not get the value from a different local file?
I have also tried running this in Safari on the desktop with local files and the same issue occurs.
When you are opening the files locally, i.e. using the file:// protocol, as of now the browsers can not determine what is "same domain" so every file is considered a separate domain. Thus you can not use localStorage when you're opening the files.
Here is some more information on the problem in FireFox: https://bugzilla.mozilla.org/show_bug.cgi?id=507361 . Personally I couldn't find much about Safari on this topic.
You can also look over this: Javascript/HTML Storage Options Under File Protocol (file://) . It might be helpful in your situation.
At this time, local files rendered via WKWebView on iOS 10 share access to the "same domain" with respect to localStorage. Unclear whether this is by design or a bug, however.

localStorage access from local file

I am creating 2 HTML files that will be stored an an iPhone locally and accessed through a WebView.
I am wondering if it is possible to set localStorage in one file, and get the results of the storage from the other file.
I know that localStorage is accessible from files on the same domain, however, it appears that you can not get the value from a different local file?
I have also tried running this in Safari on the desktop with local files and the same issue occurs.
When you are opening the files locally, i.e. using the file:// protocol, as of now the browsers can not determine what is "same domain" so every file is considered a separate domain. Thus you can not use localStorage when you're opening the files.
Here is some more information on the problem in FireFox: https://bugzilla.mozilla.org/show_bug.cgi?id=507361 . Personally I couldn't find much about Safari on this topic.
You can also look over this: Javascript/HTML Storage Options Under File Protocol (file://) . It might be helpful in your situation.
At this time, local files rendered via WKWebView on iOS 10 share access to the "same domain" with respect to localStorage. Unclear whether this is by design or a bug, however.

Loading a local image with JavaScript/jQuery where I know the location, but not the file name

The new version of Linux Mint allows HTML 5 login window themes -- I'm trying to write one that will grab each user's wallpaper. These wallpapers are located in the folder /home/#USER#/.cache/wallpaper/, however the file name is not consistent and I need a programmatic way of determining it. Once I know the filename, the login screen will display the image correctly using the file:///.. format.
I don't have any tools other than client-side HTML/CSS/JavaScript[/jQuery/etc] available to me. Is there any way I can grab the file names in that directory, so that I can grab the wallpaper image?
EDIT: Figured it out! The browsers won't allow access to the file:/// resources at all, the mdm-theme-emulator will.
It looks like these files are located on the client machine, in which case you would not be able to access them using jQuery. Javascript does not have access to the local file system.
If you are sending the request through a server, you'd be able to use the server-side code (ASP.NET, PHP, etc.) to loop through the filenames

JavaScript read file contents

how can you retrieve the data from a document with javascript that isn't the page you are on if you have the url of the new document.
what i am trying to do is create a page that has a text field for providing a local file name and a button that retrieves the words from the document provided.
thanks.
HTML5 has a File API that lets you read local files. It's supported in at least Firefox (3.6 and later, I think) and Chrome. I don't know if any other browsers support it yet or not. If you need to support other browsers, you'll have to fall back to something like Flash, but I don't have any experience with that.
Unfortunately, by default Chrome doesn't allow local files to access other local files (each file is considered to be from its own domain). You can explicitly allow it by adding the --allow-file-access-from-files flag when you launch Chrome.
Here's a good introduction to the File API with several examples: http://www.html5rocks.com/en/tutorials/file/dndfiles/.
Browser security does not allow direct access to the local filesystem. If it could, web pages would be able to steal any file of your machine.
HTML5 local storage does allow local access, but on a different principle.

Categories

Resources