I have a very specific challenge where a self contained website and assets are stored in a location that is not a web server and cannot be a web server.
I need to be able to provide staff a stand alone index.html file that they can run from their local computer which will reference the online location as a sort of external storage repository.
The website has a lot of assets and javascript... in many cases the javascript calls to assets using local paths such as images/image_file.png
Without manually updating all the asset paths within the website code, modifying hosts file... using iframe... is there a way with javascript alone to add prefix to all paths that come after in the document?
Almost like defining or setting origin which I don't believe is possible.
I had thought to read the code in with a parser and try and regex replace but was hoping for a simpler solution.
Thanks in advance for your consideration.
Related
I have read several posts on this site that ask similar questions but the key difference is they involve a client and a server. For my use, this is not the case. I am simply pasting a file directory on my computer into my browser in order to view a local HTML file, packed with CSS and some jQuery.
I've been looking around and the answers I've found are "No; a client can not write to a server", and "No; a server can not write to a client". But there is no answer to "can a client write to a client with JavaScript?"
Use case:
I'm building a webapp (website? JS app?) as a college project for a stock management tool that will be locally hosted and never connect to the internet. Sure, I could knock one together in python in a couple hours, but I wouldn't learn anything. I need to create an access a txt file containing an array of the current stock of all the items so that when the application is loaded, the user doesn't have to manually enter anything but the changes to stock levels.
Honestly, I'm a beginner at JS and JQ and I'm only going off of what makes sense based on a mix of HTML and Python that I know.
Maybe PHP would be the better option for this particular option, or maybe JS will work well enough.
You still won't be doing client-to-client, your browser will just act as though the local file system is the server using the file:// protocol which means the same rules about a "client" (the browser) cannot write to a "server" (your local file system) apply.
If you wan't to be able to write an application that can interface directly with the filesystem, then look into something like Electron which is essentially an augmented website that gives you APIs to interact with the actual computer the app is being run on, including filesystem stuff.
Being new to .htaccess concept, I have a basic question.
I tried to protect a directory which hosts my stored procedure files... this is because I need not anyone else accessing the code of the file. My issue is the following:
When I try to access a file of the directory through javascript as part of my coding, the same pop up comes up requiring username and password. How can this be resolved?
Please advise if the route I am taking is wrong.
My intention is that the code should have access to stored procedure files, but none should have access to the actual file content. This can be applicable for css files or javascript files as well.
You can't differentiate between a client asking for a resource because your code asked it to and the same client asking for a resource for some other reason.
Even if you could, then the resource would still be available to the owner of the client, without making another request for it, through (for example) the developer tools built into most browsers.
If the files you're talking about are all Javascript then protecting them like that isn't really feasible. They are client-side scripts, meaning they need to be downloaded by the user's browser. Unfortunately, you can't reliably tell the difference between a browser downloading them as part of an HTML page, and a user downloading them directly to steal them.
The best you can do is obfuscate the files to make them difficult to understand. That will never prevent a determined code thief though.
I have a Chrome packaged app that has taken me a while to get my head around but I finally have it working. However I have now come across another problem.
Is it possible to save a variable from my app into a text file that's placed in my app/file directory?
I have looked over the chrome.fileSystem api but I don't really understand it.
I could be completely wrong and maybe you can't save files to the file directory?
Any examples or tutorials on this would be great!
Thanks!
I would suggest storing the file's contents in chrome.storage and then dynamically loading and saving the contents of your css file from there instead of using the filesystem. To me, this would be much easier to accomplish.
chrome.storage sounds like a good fit all right (though not too sure about your specific needs in accessing the css outside the app). It's main use case is for saving state and storing configuration settings/variables.
We've a code lab that walks through all kinds of chrome apps stuff, including chrome.storage here: http://developer.chrome.com/trunk/apps/app_codelab5_data.html
There's also the new syncFileSystem API, which really doesn't seem to fit your needs. This is document/file level synchronization, like getting access to user's files on hard drive, saving them in app, and syncing them.
But sure, if you are curious, here's the docs on working with Chrome File System and sync File System: http://developer.chrome.com/trunk/apps/app_storage.html
We're also working on a doc that explains the key concepts around storing data in the cloud (specifically for packaged apps). Hoping to have an early cut in trunk over the next week or so.
Keep us posted on how you get on!
I just want to know if there is an object to access a folder path which includes list of clips in javascript.
Which object I should use to list clips in a folder? Actually I can't use all objects, only provided for Ecmascript.
JavaScript/Ecmascript cannot see the local filesystem. If it could then we'd have web pages sniffing all of our files without our consent.
JavaScript doesn't get to see the user's file system. That'd be a huge security problem for everyone everywhere. If you're referring to the server's file system then you probably already have a better language like php that can list the directory contents and dynamically generate the JS before it is sent to the browser.
I'm sorry if this question has been asked before, but I can't seem to find an answer for it anywhere else.
I am running a local tomcat instance using eclipse and wtp. When the local server is running, I have to use the url http://localhost:8080/appName in order to access it.
I have been using relative URLs to use my javascript and css, but now I would like start using namespaced URLs, such as domain.com/admin/users. I can't use relative css and javascript resources with these urls, since there is no javascript in the admin directory.
How can I use css and javascript resources from either my development or my production context? Is there a way to use my local tomcat instance from the ROOT context, as I can do in production? Do I have to use something to build the URLs for my resources (I would have to do this a lot, in both struts2 jsps, as well as sitemesh) ?
Don't think it's a good idea to hard code the domain urls. You can always work with the root context of your web application. You can use request.getContextPath() to know your context root. Your js/css should be under this. So you can access it like "<%=request.getContextPath()%>/js/some.js". So even when the context root changes you do not have to do any code changes. I have used the scriplet here as an example.