[英]How to get array of files from a folder using Javascript
Scenario: I am creating a personal home page that i plan for using in safari/chrome/Firefox and I have a folder with images. 场景:我正在创建一个个人主页,计划在safari / chrome / Firefox中使用它,并且我有一个包含图像的文件夹。 I want to display a random image as the background of the page.
我想显示一个随机图像作为页面的背景。
My solution to this was to create an array with all the images as separate links as the objects of the array. 我对此的解决方案是创建一个数组,其中所有图像作为该数组的对象作为单独的链接。 My JS works with a pre-made array of links but I have no clue on how to create an array from a directory.
我的JS使用预制的链接数组,但是我不知道如何从目录创建数组。
I don't mind using jquery if required but i cant have server side php (or anything else) since i am linking the local html file to the new tab page.\\ 我不介意使用jquery(如果需要),但由于我将本地html文件链接到新标签页,因此我无法安装服务器端php(或其他任何工具)。\\
The html file is in the directory / and the images in /img . html文件位于目录/中,图像位于/ img中。
This can't be done. 无法做到这一点。 You're going to need something on the server side to read the directory that is on your server .
你将需要在服务器端的东西读这是你的服务器上的目录。 Javascript (including jQuery) running on the user's browser doesn't have access to list directories on your server.
在用户浏览器上运行的Javascript(包括jQuery)无权访问服务器上的列表目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.