473,387 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Javascript read web directory

I need to make a javascript read a web directory from a remote site (ie
"http://remotesite.com/images")
(The remote die does not have an index.htm and does have directory
listing enabled)

I have seen many samples but they all use frames or iframes, all I want
is a method that you can say
<body onload="readremotedir('http://remotesite.com/images');">

and the method would get the directory listings and populate an array
var Pic = new Array()

Sorry in advance for something that may be easy, I know little about
Javascript

Are there any samples that dont use frames/iframes

Thnanks, Ed,

Aug 17 '06 #1
3 10309
What server do you use? Typically the server is going to send back some
HTML formatted response that is not consistent with other servers.

But the general gist is to create a XMLHttpRequest to send the request
to the specified URL asynchronously. Then in your callback method read
the response. This is where you'll need to know something about what
the server sends back. Parse that response and use it to build your
HTML output.

Are you familiar with XMLHttpRequests? If so this should be pretty
easy, if not, then you get to learn something new.

I know it's a pretty generic response, but HTH anyway. Without more
details about what the server is sending back to you it's hard to be
much more help.

Aug 17 '06 #2

gencode wrote:
I need to make a javascript read a web directory from a
remote site (ie "http://remotesite.com/images")
(The remote die does not have an index.htm and does have
directory listing enabled)

I have seen many samples but they all use frames or
iframes, all I want is a method that you can say
<body
onload="readremotedir('http://remotesite.com/images');">
Here's an ugly hack for you. Note that it was only tested
with Apache/2.0.53 under MSIE 6.0 and Firefox 1.5. It
almost certainly won't work with other servers (and
probably even with different versions/configurations of
Apache). If you really want a robust function, you'll just
have to roll up your sleeves and make it work.

function get_apache_dirlist ( url )
{
var http ;
if ( window . XMLHttpRequest )
{
http = new XMLHttpRequest ( ) ;
}
else
{
http = new ActiveXObject ( 'microsoft.XMLHTTP' ) ;
}
http . open ( 'GET' , url , true ) ;
http . onreadystatechange =
function ( )
{
if ( http . readyState == 4 )
{
parse_apache_dirlist ( http . responseText ) ;
}
return ( true ) ;
} ;
http . send ( null ) ;
return ( true ) ;
}

function parse_apache_dirlist ( html )
{
var doc ;
pseudo_xml = new String
( '<' + '?xml version="1.0"?>' + html ) ;
pseudo_xml = pseudo_xml . replace
( /<!DOCTYPE .*?>/g , '' ) ;
pseudo_xml = pseudo_xml . replace
( /<(\w)r>/g , '<$1r />' ) ;
pseudo_xml = pseudo_xml . replace
( /<img (.*?)>/g , '<img $1 \/>' ) ;
if ( window . DOMParser )
{
doc = new DOMParser ( ) ;
doc = doc . parseFromString
( pseudo_xml , 'text/xml' ) ;
}
else
{
doc = new ActiveXObject ( 'microsoft.XMLDOM' ) ;
doc . loadXML ( pseudo_xml ) ;
}
var anchors = doc . getElementsByTagName ( 'a' ) ;
var hrefs = new Array ( ) ;
for ( var i = 0 ; i < anchors . length ; i ++ )
{
var href = anchors [ i ] . getAttribute ( 'href' ) ;
if ( ! href . match ( /^[\?\/]/ ) )
{
hrefs . push ( href ) ;
}
}
return ( hrefs ) ;
}

--
roy axenov

Aug 18 '06 #3
Thanks Roy

p.*****@ctncorp.com wrote:
gencode wrote:
I need to make a javascript read a web directory from a
remote site (ie "http://remotesite.com/images")
(The remote die does not have an index.htm and does have
directory listing enabled)

I have seen many samples but they all use frames or
iframes, all I want is a method that you can say
<body
onload="readremotedir('http://remotesite.com/images');">

Here's an ugly hack for you. Note that it was only tested
with Apache/2.0.53 under MSIE 6.0 and Firefox 1.5. It
almost certainly won't work with other servers (and
probably even with different versions/configurations of
Apache). If you really want a robust function, you'll just
have to roll up your sleeves and make it work.

function get_apache_dirlist ( url )
{
var http ;
if ( window . XMLHttpRequest )
{
http = new XMLHttpRequest ( ) ;
}
else
{
http = new ActiveXObject ( 'microsoft.XMLHTTP' ) ;
}
http . open ( 'GET' , url , true ) ;
http . onreadystatechange =
function ( )
{
if ( http . readyState == 4 )
{
parse_apache_dirlist ( http . responseText ) ;
}
return ( true ) ;
} ;
http . send ( null ) ;
return ( true ) ;
}

function parse_apache_dirlist ( html )
{
var doc ;
pseudo_xml = new String
( '<' + '?xml version="1.0"?>' + html ) ;
pseudo_xml = pseudo_xml . replace
( /<!DOCTYPE .*?>/g , '' ) ;
pseudo_xml = pseudo_xml . replace
( /<(\w)r>/g , '<$1r />' ) ;
pseudo_xml = pseudo_xml . replace
( /<img (.*?)>/g , '<img $1 \/>' ) ;
if ( window . DOMParser )
{
doc = new DOMParser ( ) ;
doc = doc . parseFromString
( pseudo_xml , 'text/xml' ) ;
}
else
{
doc = new ActiveXObject ( 'microsoft.XMLDOM' ) ;
doc . loadXML ( pseudo_xml ) ;
}
var anchors = doc . getElementsByTagName ( 'a' ) ;
var hrefs = new Array ( ) ;
for ( var i = 0 ; i < anchors . length ; i ++ )
{
var href = anchors [ i ] . getAttribute ( 'href' ) ;
if ( ! href . match ( /^[\?\/]/ ) )
{
hrefs . push ( href ) ;
}
}
return ( hrefs ) ;
}

--
roy axenov
Aug 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dean | last post by:
Hi I've got a question relating to using Javascript on an Intranet. I have a directory with a list of files in the format week36.xls, week37.xls and I want to write a script that will scan...
5
by: Doug | last post by:
I would appreciate a response on this. I have clients who will be placing text files information about in a network directory for example: http://www.protegen.com/clients/ Is it possible to...
3
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change...
4
by: mscir | last post by:
I would like to generate a page of links including some of the pdf properties (title, author, version, etc.) for a folder full of pdf's. Is this possible from Javascript? TIA, Mike
7
by: Bert | last post by:
I have been reading the post and the FAQ and have been unable to find anything that will help with my problem. First let me say that I am not a web developer, designer and no next to nothing...
9
by: Robby Bankston | last post by:
I'm working on some code and am running into brick walls. I'm trying to write out Javascript with Javascript and I've read the clj Meta FAQ and didn't see the answer, read many similar posts (with...
23
by: Han | last post by:
Our app runs on end-users machines (apache2.x + php5). At this moment it is quite easy for someone (who has access to the console) to insert a couple lines of php code to steal sensitive info. ...
3
by: stephen | last post by:
Hi, I have a javascript file that I want to use on a button. If I have the javascript file in the same folder as the webform then it works for eg: /SampleApp/WebForms/TestForm.aspx but I...
5
by: Hannes | last post by:
Hi, How can I read the Content of a directory in my HTML-structure, and show it with an alertbox or something. What I actually want, a Photo-Page. If i load the page, My browser have to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.