Allowing clients to open files on their own system

I

Ian Rastall

I've got a small search page at http://www.sundry.ws/search.html and
I would like to add a section that allows me to open files on my
computer, instead of having to go to File > Open. It's just slightly
easier that way.

This is the code I've written to do that:

<form id="file">
<table id="file-open" summary="For opening local files">
<colgroup span="2"></colgroup>
<tbody>
<tr>
<td>
<p>File:</p>
</td>
<td>
<input type="file" id="upload-box" size="20" maxlength="255"
onchange="window.location.href = forms[3].elements[0].value" />
</td>
</table>
</form>

It works in IE 6 SP2, but not in Firefox 1.6 or Opera 8.0. Opera
does nothing, and Firefox gives me an error that "C is not a
registered protocol". Could someone possibly tell me why this isn't
working, and how to fix it?

TIA,
Ian
 
C

Christopher J. Hahn

Ian said:
I've got a small search page at http://www.sundry.ws/search.html and
I would like to add a section that allows me to open files on my
computer, instead of having to go to File > Open. It's just slightly
easier that way.

This is the code I've written to do that:

<form id="file">
<table id="file-open" summary="For opening local files">
<colgroup span="2"></colgroup>
<tbody>
<tr>
<td>
<p>File:</p>
</td>
<td>
<input type="file" id="upload-box" size="20" maxlength="255"
onchange="window.location.href = forms[3].elements[0].value" />
</td>
</table>
</form>

It works in IE 6 SP2, but not in Firefox 1.6 or Opera 8.0. Opera
does nothing, and Firefox gives me an error that "C is not a
registered protocol". Could someone possibly tell me why this isn't
working, and how to fix it?

Need to use a known protocol or pseudo-protocol (http:, ftp:, mailto:).
In this case, use file:
window.location.href = 'file:///' + forms[3].elements[0].value

Hope that does it for you.
 
A

ASM

Ian said:
I've got a small search page at http://www.sundry.ws/search.html and
I would like to add a section that allows me to open files on my
computer, instead of having to go to File > Open. It's just slightly
easier that way.

you have to open a same file in each browser and to see
what they give as url (location bar)

then do the same with <input file
-> onchange="alert(this.value)"

compare and make JS for corrections according to each browser

i.e. on my Mac url given by input is :
file://hard_drive/folder/file.htm
or
file:///hard_drive/folder/file.htm
or
hard_drive/folder/file.htm

and rigth url in location.href
would be : file://hard_drive/folder/file.htm
 
I

Ian Rastall

In this case, use file:
window.location.href = 'file:///' + forms[3].elements[0].value

Thanks, Christopher. It works now in Firefox and IE, though still
not on Opera. That might be okay for now. (Not that I uttered the
previous sentence.) :)

Ian
 
I

Ian Rastall

compare and make JS for corrections according to each browser

i.e. on my Mac url given by input is :
file://hard_drive/folder/file.htm
or
file:///hard_drive/folder/file.htm
or
hard_drive/folder/file.htm

Ah, I see! I notice in Opera that they use file:// instead of
file:///, which probably caused the problem. I'll have to dig around
for a quick browser check and write a bit more code. Thanks!

Ian
 
I

Ian Rastall

compare and make JS for corrections according to each browser

i.e. on my Mac url given by input is :
file://hard_drive/folder/file.htm
or
file:///hard_drive/folder/file.htm
or
hard_drive/folder/file.htm

Okay, I've written some extra code, in the head section, as follows:

<script type="text/javascript">
function detect() {
if (navigator.userAgent.indexOf("Opera")) {
window.location.href = 'file://' + forms[3].elements[0].value;
} else {
window.location.href = 'file:///' + forms[3].elements[0].value;
}
}
</script>

The problem is, that I get a JS error stating that "forms" is not a
recognized variable. I tried moving the function to the bottom of
the page, but that didn't help either. I'm a bit stumped, I'm
afraid, and have to get over *this* hump in order to just test the
function on various browsers! <sigh>

Thanks again for any help,
Ian
 
R

Randy Webb

Ian Rastall said the following on 7/27/2005 11:02 PM:
compare and make JS for corrections according to each browser

i.e. on my Mac url given by input is :
file://hard_drive/folder/file.htm
or
file:///hard_drive/folder/file.htm
or
hard_drive/folder/file.htm


Okay, I've written some extra code, in the head section, as follows:

<script type="text/javascript">
function detect() {
if (navigator.userAgent.indexOf("Opera")) {
window.location.href = 'file://' + forms[3].elements[0].value;
} else {
window.location.href = 'file:///' + forms[3].elements[0].value;
}
}
</script>

The problem is, that I get a JS error stating that "forms" is not a
recognized variable. I tried moving the function to the bottom of
the page, but that didn't help either. I'm a bit stumped, I'm
afraid, and have to get over *this* hump in order to just test the
function on various browsers! <sigh>

document.forms[..........

IE is the worst browser to test in. But I am still wondering why you are
trying to write a "cross-browser" file opening script if it is only for
your personal use....
 
R

Randy Webb

Danny said the following on 7/26/2005 12:51 AM and in his typical
moronic style didn't quote what he was babbling about:
As told, just do a onchange="alert(this.value)" to see how much
it gives, I don't think you'd get the fullpath and/or if you'd get
anything at all, type="file" doesn't give much access intentionally so,
due to security issues for filename integrity.

Pure nonsense. Perhaps you should test what you are babbling about
before babbling about it.

It's possible, never bothered myself, you don't have such access and IE does give it.

I thought you said about it might not be possible, yet now you say "It's
possible". Make up your mind.
 
I

Ian Rastall

I am still wondering why you are trying to write a "cross-browser"
file opening script if it is only for your personal use....

That's a good question, but it's not exactly for just my personal
use. There may be a *few* people who use this page. IMO it's very
handy, and thought it would catch on, but ... it didn't.
Nevertheless, I had it working on IE and Firefox, at least when it
was on my local machine. Now that I've uploaded it, it generates
security errors. <sigh> Here's the URL:

http://www.sundry.ws/search.html

Is there any way around this problem? It's handier, especially for
testing web pages, than using the menu system. (At least IMO.)

Ian
 
I

Ian Rastall

Thanks for your advice, all. I've given up on trying to get around
JS security issues, which I figure is pointless anyway, and have
added something totally different (and much simpler to the page.)

Thanks again!
Ian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top