By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,508 Members | 1,856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,508 IT Pros & Developers. It's quick & easy.

Allowing clients to open files on their own system

P: n/a
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
--
http://www.bookstacks.org/
Jul 28 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Ian Rastall wrote:
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
TIA,
Ian
--
http://www.bookstacks.org/


Hope that does it for you.

Jul 28 '05 #2

P: n/a
ASM
Ian Rastall wrote:
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
--
Stephane Moriaux et son [moins] vieux Mac
Jul 28 '05 #3

P: n/a
On 27 Jul 2005 19:26:07 -0700, Christopher J. Hahn wrote:
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
--
http://www.bookstacks.org/
Jul 28 '05 #4

P: n/a
On Thu, 28 Jul 2005 04:33:00 +0200, ASM wrote:
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
--
http://www.bookstacks.org/
Jul 28 '05 #5

P: n/a


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. It's possible, never bothered
myself, you don't have such access and IE does give it.

Danny

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 28 '05 #6

P: n/a
On Thu, 28 Jul 2005 04:33:00 +0200, ASM wrote:
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
--
http://www.bookstacks.org/
Jul 28 '05 #7

P: n/a
Ian Rastall said the following on 7/27/2005 11:02 PM:
On Thu, 28 Jul 2005 04:33:00 +0200, ASM wrote:

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....

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 28 '05 #8

P: n/a
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 28 '05 #9

P: n/a
On Thu, 28 Jul 2005 00:03:22 -0400, Randy Webb wrote:
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
--
http://www.bookstacks.org/
Jul 28 '05 #10

P: n/a
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
--
http://www.bookstacks.org/
Jul 28 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.