Folder directory reading in javascript [duplicate] - javascript

This question already has answers here:
Local file access with JavaScript
(14 answers)
Closed 3 years ago.
I try to display windows explorer view as a static web page. We have to read a root folder and display all the folders and files as a static webpage. We have to use only client side programming. I know it is possible with the help of server side programming. My question is, is it possible to achieve it in front end without involving backend. I have only one problem which is reading the folder structure. How can I do it? I need to load a html file(ex..C:\workspace\treeview\index.html) in the browser and it should display all the files and folder. Also share your suggestions to achieve the above scenario?

The short answer here is no. Browsers are disallowed from accessing the local file system in this way. Even a simple iframe with a local src will throw errors in the Console.
<iframe src="C:\" width="600" height="480"></iframe>
Without getting into (or fully understanding) them, there are severe security implications if JavaScript is allowed to access the local filesystem. Imagine how dangerous malicious JS code could be if it was allowed.

Related

Open a local xml file using javascript [duplicate]

This question already has answers here:
XMLHttpRequest cannot load file:///C:/Users/hamma/Desktop/rao.html
(2 answers)
Closed 5 years ago.
I'm trying to open a .xml storared on my own PC using javascript and do some stuff,just for knowledge, in order to do that, I've
found a example on site
https://www.w3schools.com/js/js_ajax_xmlfile.asp which uses AJAX and the object XMLHttpRequest, but, it does not work like the example showed in the site, I understand that the problem is that AJAX uses a server, so, I wonder if there is another solution to do that without a server, I just want to work with the file on my own pc or on a shared network like for example when we uses a shared workbook on excel.
Thanks in advance.
The security model for Javascript in browsers does not allow you to open local files. If you are wanting to do something like this using Javascript, you would need to look into installing something that runs outside the browser like Node.js.
https://nodejs.org/

Difference between using local JS and JS from CDN [duplicate]

This question already has answers here:
What are the advantages and disadvantages of using a content delivery network (CDN)? [closed]
(4 answers)
Closed 7 years ago.
I am trying to write a JavaScript script to populate HTML using jQuery and Bootstrap. In many tutorials on the internet, tutors mention to using files from a Content Delivery Network(CDN) instead of calling those files locally.
But I am unable to foresee any advantage making a call to js or CSS over a network, instead of loading it locally, which should prove good enough.
I am eager to know, what is the difference in terms of network and machine resources as well as the load on a page.
Pros using CDN:
* cache for the library in the client side.
Cons using CDN:
* If the cdn's site is down, your site will not get the files.
* Cdn file changes frequently and therefore your production site will work with the newest files that you didn't checked them(this can be very dangerous).
Now you can think if this suitable for your site.

I want to make php Application standalone [duplicate]

This question already has answers here:
Convert a PHP script into a stand-alone windows executable
(7 answers)
Closed 9 years ago.
I want to make windows standalone app with php, even i want to use database, javascript in that application.
Note : i don't want to give source code to user.
I should be like exe file which user can run.
If going with Windows, try WinBinder. It allows you to develop native Windows applications using PHP.
It also supports SQLite, so you don't need a database server
Also this answer will help you
I use phc to create .exe files out of my PHP source code. It works quite well, but it's mostly good for console applications rather than full webpages.
However, you could have your PHP script include a basic "server" that allows the browser to communicate with it - I have done this in the past too, and while it might seem daunting the results were very rewarding.

How do you hide Javascript? [duplicate]

This question already has answers here:
How do I hide javascript code in a webpage?
(12 answers)
Closed 9 years ago.
I have a site where I display charts using JS data. I don't want other people to copy my source (meaning have them copy paste my html/JS, etc.). I have seen other websites with charts and if you view the source there is no data there. Are they doing something sneaky? How do I do that? Can you run it on the server side? Can you put it in another file and reference that one? I have the JS linked from an external file but you can still see all the a data in that one if you open it. What is the best way to keep the data from appearing in the source file? I'm not talking about obfuscating it.
Please read this related post:
This thread: How do I hide javascript code in a webpage?
Basically, if a web browser can read it, the end user can access it.
If you wanted to really make it more work to view the source, you would do all of the following:
Put it in an external .js file.
Obfuscate the file so that most native variable names are replaced
with short versions, so that all unneeded whitespace is removed, so
it can't be read without further processing, etc...
Dynamically include the .js file by programmatically adding script
tags (like Google Analytics does). This will make it even more
difficult to get to the source code from the View Source command as
there will be no easy link to click on there.
Put as much interesting logic that you want to protect on the server
that you retrieve via ajax calls rather than do local processing.
You can't hide your JavaScript since it has to execute client side. You can move all your js to external files, but that will not really hide it since someone can just reference the same files.
Basically the key point is that nothing done in JavaScript can be kept a secret from a skilled developer. JavaScript is inherently in plain text.

How to hide javascript file of your website? [duplicate]

This question already has answers here:
How can I obfuscate (protect) JavaScript? [closed]
(22 answers)
Closed 8 years ago.
I have written a lot of functions which use ajax to call PHP functions in my main.js file. The problem is that anyone can see my logic and internally called php file names of website by viewing the page source. How should I prevent the people from viewing my javascript file?
Javascript can be obfuscated, but there's nothing that's going to prevent a client from
seeing the URL strings in your code, or
simply inspecting the HTTP requests themselves to determine what URLs are being hit.
This re-enforces the importance of making sure you write solid and secure server-side code. You also want to make sure your web server is configured and secured properly, so that (for example) clients are unable to download the PHP source directly.
You can't stop people from viewing your javascript file, because the readable javascript code is required to correctly execute that code on your page. You can obfuscate the function names and minify the javascript to make it harder to read, but if someone wants to read the file, this will not stop them from doing so.
Instead, you should assume that everyone knows everything about your javascript file, and that everyone is able to alter your javascript file. You shouldn't put any validation solely in your javascript file and in every php page you should somehow check if the request that is made is valid (e.g. was the user allowed to do an ajax request to a certain page at a certain time?).
You can't able to hide the Javascript in browser, If you did that, your javascript related operations won't run.
you cannot hide javascript files. but you can minify the code so that, it will be very difficult for a man to read and understand your logic and all.
something like this
http://code.jquery.com/jquery-1.10.1.min.js

Categories