View Full Version : Netscape problem
zach1234
10-07-2004, 08:30 AM
I have a form that contains a select with "onchange". Here is a part of this code:
<form action="" method="get">
<input type="hidden" name="shown" value="yes">
<select name="fname" size=4 onchange="window.location.href=this.options[this.selectedIndex].value;">
This of course is followed by code that generates options, etc.
This form allows to select and view a file. It works perfectly well under IE, but when I run it under Netscape, it returns an alert "c is not a registered protocol" when I attempt to view the selected file.
Javascript console displays the following:
Error: uncaught exception: [Exception... "Component returned failure code: 0x804b0012 [nsIDOMLocation.href]" nsresult: "0x804b0012 (<unknown>)" location: "JS frame :: <unknown filename> :: onchange :: line 0" data: no]
Now, this apparently suggests I should have some code to handle exceptions. How should I do that? Or is there a way something can be done in browser's "Preferences"?
Thanks
ElectricSheep
10-07-2004, 03:38 PM
I think there is an error elsewhere in your code.
The following works fine in Netscape 4+ and others:
<form action="" method="get">
<input type="hidden" name="shown" value="yes">
<select name="fname" size="4" onchange="window.location.href=this.options[this.selectedIndex].value;">
<option value="home.htm">Home
<option value="about.htm">About
<option value="links.htm">Links
</select>
</form>
HTH
zach1234
10-08-2004, 08:45 AM
It works from the standpoint of being able to select something. But once selected, the content of the file should be displayed. This is no problem under IE, but somehow Netscape does not recognize the file format (is it MIME type?). Is there something in Javascript that forces a known MIME type to be associated with the file extensions of these files?
Thanks for validating the code in the form, though.
ElectricSheep
10-08-2004, 02:00 PM
Hi there.
The code I posted does what you describe including loading the selected page.
What do the actual URLs you are selecting look like? They may contain characters causing the issue.
Don't use backslashes in the URL - that's a Microsoft only thing.
Not :
\pages\mypage.htm
but
/images/mypage.htm
Your error mentions 'c', that makes me think the URL contains a reference to your c drive and because you may be using Microsoft backslashes or too many forward slashes, for example, you will have a problem in anything but IE.
senshi
10-10-2004, 07:20 PM
im sorry what was that about only a M$ thing??
/ is for URL as in protocol://URLaddress/location/file.htm
and
\ is for local machine drive:\folder\file.ext
\ is also the escape character combo for use with \" \' \\ for example when used in javascript strings.
ElectricSheep
10-11-2004, 06:59 AM
Hi there.
\ is only used by MS for local machine paths, UNIX, OpenBSD, Linux etc use forward slashes for local and URL paths - if you are having your site hosted on a non-Microsoft platform beware.
Microsoft platforms will take both types of slash so you may as well stick to the cross-platform, forward-slash approach - unless you are using absolute paths on a Microsoft platform.
Back slash is best reserved for escaping.
HTH
senshi
10-13-2004, 06:27 AM
http://www.w3.org/Addressing/rfc1738.txt
Basically says what I said previously.
2.3 Hierarchical schemes and relative links
In some cases, URLs are used to locate resources that contain
pointers to other resources. In some cases, those pointers are
represented as relative links where the expression of the location of
the second resource is in terms of "in the same place as this one
except with the following relative path". Relative links are not
described in this document. However, the use of relative links
depends on the original URL containing a hierarchical structure
against which the relative link is based.
Some URL schemes (such as the ftp, http, and file schemes) contain
names that can be considered hierarchical; the components of the
hierarchy are separated by "/".
ElectricSheep
10-13-2004, 02:05 PM
.....But backslash is for Microsoft local paths so best avoided in favour of forward slash which is used for UNIX local paths and, of course, URLs :
For example, if using absolute references, use
<a href="C:/somefolder/somesubfolder/somefile.htm">Click</a>
Instead of
<a href="C:\somefolder\somesubfolder\somefile.htm">Click</a>
To make it cross-platform (although UNIX-based systems would not have a drive letter)
AaronCampbell
10-13-2004, 02:39 PM
Just so that everyone knows, \'s are used for escaping, and as a folder delimiter on MICROSOFT OS's (windows, MS-DOS). The / is used for folder delimiting on everything else (linux, BSD, unix, and as a standard on the WEB).
zach1234
10-13-2004, 03:26 PM
All right, here is exactly what I am generating:
<form action="" method="get">
<input type="hidden" name="shown" value="yes">
<select name="fname" size=4 onchange="window.location.href=this.options[this.selectedIndex].value;">
<option value="c:\project/some_directories/filea.tp">filea</option>
<option value="c:\project/some_directories/fileb.prc">fileb</option>
....
....
...etc...
<option value="c:\project/some_directories/filez.prc">filez</option>
</select>
</form>
Now, what is wrong with it? Again, under IE I can display the content of "filea" (or any other specified as an option),
but Netscape does not like the "protocol". Is there a way to hide "c:"? And yes, I tried using "c:/" instead of "c:\", with exactly the same result. I also tried things like "file://c:\", by the way.
senshi
10-13-2004, 08:13 PM
if your serving up from your own machine, you have to put anything you wish to serve up within the servers scope, this means you would either add in a folder as an alias or as a folder within the servers root.
Your server addressing:-
protocol://domain:port/alias/location/file.ext <- Absoloute addressing
/alias/location/file.ext <- relative addressing
you need to specify relative addressing in URLs and these are anything past the 'protocol://domain:port' this leaves you with anything past the root / or the /alias root as shown above.
SO...
<option value="./project/some_directories/filea.tp">filea</option>
or
<option value="/project/some_directories/filea.tp">filea</option>
should do what your looking to do, return a path thats relative in the value.
IM assuming that
http://www.yourserver.org/project/some_directories/filea.tp is where the filea file exists.
ElectricSheep
10-14-2004, 05:43 AM
If you want to keep the reference to the 'c' drive then this should work :
<option value="file://C:/somefolder/somesubfolder/somepage.htm">Some page</option>
[ Tested successfully on IE6, NN4, NN7 ]
senshi
10-14-2004, 06:55 AM
Yes but, if the page is on the internet in an ISP assigned webspace, the file://c:/ would be looking on the surfers machine c: for the file, thats why you bring items like that into the servers scope and apply a relative path or alias.
zach1234
10-14-2004, 09:57 AM
I changed to this format: "file://c:/directory/subdirectory/.../file.ext", as ElectricSheep suggested.
Now instead of the "c protocol" complaint, it simply does not display the file. Javascript console says:
"Error: Access to 'file:///c:/directory/.../filea.tp' from script denied"
and
"Error: uncaught exception: [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "<unknown>"]".
Again, this only happens with Netscape. I presume that senshi is right, there is a confusion between finding the file on the server or on the client. But why this does not bother the IE?
Also, I may want to modify the DirectoryRoot value of "httpd" file for the Apache, to point to a place common to both where the application and files of interest (filea, etc) are located. Then I can switch to relative addressing.
ElectricSheep
10-14-2004, 04:18 PM
This is actually now a security issue, Mozilla/Netscape doesn't allow linking to local files from Web content unless it is set up in your preferences file hence the access denied message.
If you are going to do this you'll need something like the line user_pref("security.checkloaduri", false); in your Netscape profile's user.js file.
IE does not currently impose the same level of strictness although it may do once you have installed SP2.
senshi
10-14-2004, 07:53 PM
And like I keep reiterating, far easier just to move the B****y file into the servers scope, sloves lots of issues and is far more tidy than making several setting changes.
Any file within your servers scope will be automatically accessable, linking to the file from a relative path means you then can at will transplant your site to another server anywhere on the internet and not worry about changing all the coded links and URL refs as they will be relative to the web root.
ElectricSheep
10-15-2004, 11:49 AM
Totally agree.
zach1234
10-20-2004, 11:40 AM
I abandoned this attempt to use onchange="window.location.href=this.options[this.selectedIndex].value...
Instead, once I retrieve the full path name from the "select" on the form, I use PHP to open the file and then dump the contents to a console window. This way I am using a server-side application, which gets me to the file on the server regardless whether I have IE or Netscape.
It works fine, except, of course, it is not very elegant.
Thank you all for your help.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.