473,382 Members | 1,357 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,382 software developers and data experts.

SRC parameter not working in Mozilla when path is included

(This is a re-post of something that apparently did not post correctly
the first time, so if there's more than one copy, please ignore the
duplicate).

I normally use Mozilla 1.4 on Windows XP Pro.
As I was developing some test webpages, I discovered that the SRC
parameter doesn't seem to work when a path is used with the filename.

In one example, when I want to run a JavaScript from an external file
(i.e., not inline), I would do the following ...

<SCRIPT LANGUAGE="JavaScript" SRC="program.js"> </SCRIPT>

If "program.js" were in a different subdirectory than the .htm file
referring to it, the filename would have to be prefixed by the
pathname as follows ...

<SCRIPT LANGUAGE="JavaScript" SRC="/mydir/program.js"> </SCRIPT>

But when I ran the above from within an .htm file loaded locally into
Mozilla, it did not work. (The result was as if the above code weren't
there). However, when I ran the identical code on Internet Explorer
(v.6), it worked.
In another, even simpler example, the code to put an image on a
webpage is ...

<img src="picture.jpg">

Again, if "picture.jpg were in a different subdirectory than the .htm
file referring to it, the filename would have to be prefixed by the
pathname as follows ...

<img src="/mydir/picture.jpg">

When I ran the above from within an .htm file loaded locally into
Mozilla, it did not work. (The result was as if the above code weren't
there). However, when I ran the identical code on Internet Explorer
(v.6), it worked.
By the way, I tried using backslashes instead of forward slashes. In
both cases, it still worked on Internet Explorer but not on Mozilla.
The SRC parameter seems like a fairly frequently used parameter for
the developers of Mozilla to overlook it. Is this really a bug in
Mozilla or is it just some option/switch in Mozilla that I didn't set
properly?
__________________________________
Do you Yahoo!?
Find out what made the Top Yahoo! Searches of 2003
http://search.yahoo.com/top2003
Jul 20 '05 #1
13 3264
Lee
wylbur37 said:
The SRC parameter seems like a fairly frequently used parameter for
the developers of Mozilla to overlook it. Is this really a bug in
Mozilla or is it just some option/switch in Mozilla that I didn't set
properly?


Neither.

An URL beginning with a "/" is invalid. Since it isn't relative to
the URL of the current page, you must specify the protocol. IE lets
you get away with it, assuming that you mean the "file:" protocol.

There are many reasons why it's bad for a browser to make that sort
of assumption, but they are balanced by the fact that accepting bad
code will trick some people into thinking that the other browsers
are buggy, and so they will be less likely to support them, giving
the more lenient browsers a market advantage.

The correct tag would be:

<script type="text/javascript" src="file:///C:/mydir/program.js">

You should see that format in the Location bar when you open any
local HTML file.

Jul 20 '05 #2
Lee <RE**************@cox.net> writes:
An URL beginning with a "/" is invalid. Since it isn't relative to
the URL of the current page, you must specify the protocol. IE lets
you get away with it, assuming that you mean the "file:" protocol.
It is not invalid in general. As an URI fragment, it defines an
absolute path, relative to the current protocol and server. It is
correct for IE to assume the "file" protocol and "localhost"
server. Where it gets dicey is what happens on local files.

If the URL to the local file is
file://localhost/c:/somedire/myhtml/foo.html
then using the URI fragment in that context "/mydir/program.js" should
give
file://localhost/mydir/program.js
That is most likely not what is wanted. For one thing, it doesn't include
a drive letter. I guess it is what Mozilla does (ok, let me check ... yes,
it gives
file:///mydir/program.js
which is equivalent - omitting the server name in a file protocol means
the server is localhost).

If you compare it to IE, the same test gives:
file:///D:/mydir/program.js
(my test file was on the D: drive). That is incorrect according to
the definition of URIs, but obviously works better on windows based
machines.

Mozilla also runs on, e.g., Unix machines, where there are no drive
letters, so I can see why the want to keep the code general.
There are many reasons why it's bad for a browser to make that sort
of assumption, but they are balanced by the fact that accepting bad
code will trick some people into thinking that the other browsers
are buggy, and so they will be less likely to support them, giving
the more lenient browsers a market advantage.
Hear, hear!
<script type="text/javascript" src="file:///C:/mydir/program.js">


The problem is that you need to change the file before uploading
to a server. The advantage is that it works locally :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
On 2 Jan 2004 07:02:37 -0800, Lee <RE**************@cox.net> wrote:
An URL beginning with a "/" is invalid. Since it isn't relative to
the URL of the current page, you must specify the protocol. IE lets
you get away with it, assuming that you mean the "file:" protocol.


That statement is incorrect as long as the document has a base URL; either
specified explicitly or derived from the document (it's file: or http:
URL). A URL beginning with a single forward slash would be parsed like so:

base: http://www.example.com/html/main.html

abs: /mydir/picture.jpeg -> http://www.example.com/mydir/picture.jpeg

If 'mydir' was a subdirectory in 'html', the relative URL should be:

rel: ./mydir/picture.jpeg ->
http://www.example.com/html/mydir/picture.jpeg

OR:

rel: mydir/picture.jpeg

You were correct though that a URL beginning with a forward slash is not
relative.

Using the file: scheme, the results should be similar: a single slash
would begin from the root directory of the current drive. However, RFC
1808 doesn't give examples for the file: scheme (probably due to numerous
and dissimilar filesystem formats).

<snip>

Mike
RFC 1808: http://www.cis.ohio-state.edu/cgi-bin/rfc/rfc1808.html

There is a list of examples towards the end of the document
(Section 5.1 - Normal Examples) that include a single, initial
forward slash.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #4
On Fri, 02 Jan 2004 17:37:04 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
<script type="text/javascript" src="file:///C:/mydir/program.js">


The problem is that you need to change the file before uploading
to a server. The advantage is that it works locally :)


However, the simple thing is to mirror the directory structure on the
server on the development machine(s) as well (it's what I do). If you only
use relative URLs, with '../' used as necessary, you need to change
nothing, and it works locally, too. Of course, you need to plan your
directory structures carefully first, but shouldn't you always do that?

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #5
wylbur37 wrote:
I normally use Mozilla 1.4 on Windows XP Pro.
As I was developing some test webpages, I discovered that the SRC
parameter doesn't seem to work when a path is used with the filename.

In one example, when I want to run a JavaScript from an external file
(i.e., not inline), I would do the following ...

<SCRIPT LANGUAGE="JavaScript" SRC="program.js"> </SCRIPT>

If "program.js" were in a different subdirectory than the .htm file
referring to it, the filename would have to be prefixed by the
pathname as follows ...

<SCRIPT LANGUAGE="JavaScript" SRC="/mydir/program.js"> </SCRIPT>

But when I ran the above from within an .htm file loaded locally into
Mozilla, it did not work. (The result was as if the above code weren't
there). However, when I ran the identical code on Internet Explorer
(v.6), it worked.


"/mydir/program.js" is an absolute path. On your server this is ok if
the url is "www.yoursite.com/mydir/program.js". But on the local machine
mydir is searched in the root dir - wherever this may be on Windows
machines (not C: at least on Win98).
Opera shows same results and I guess that's right.

Christian
Jul 20 '05 #6
Michael Winter <M.******@blueyonder.co.invalid> writes:
However, the simple thing is to mirror the directory structure on the
server on the development machine(s) as well (it's what I do). If you
only use relative URLs, with '../' used as necessary, you need to
change nothing, and it works locally, too.
Yes, as long as the paths are in relation to the HTML file, it is
simple. However, if your javascript files contain paths as well, it
becomes difficult. E.g., this code in an external file:

function makeMyImg() {
var img = new Image();
img.src = "../images/myImage.png";
return img;
}

The problem is that when that code is called from an HTML page, the path
is taken relative to the HTML file, not the Javascript file. If you have
HTML files in different levels of directories, no relative path will
work for all of them. That makes absolute paths necessary for Javascript
files that are shared between different pages.
Of course, you need to plan your directory structures carefully
first, but shouldn't you always do that?


Absolutely. And always sooner than you expect :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
In article <hd**********@hotpop.com>, lr*@hotpop.com enlightened us
with...
The problem is that when that code is called from an HTML page, the path
is taken relative to the HTML file, not the Javascript file. If you have
HTML files in different levels of directories, no relative path will
work for all of them. That makes absolute paths necessary for Javascript
files that are shared between different pages.


Actually, I always use relative paths because of portability, and I had
to write a workaround to just this problem.
What I did was basically check where I was and write the source element
dynamically.

It was a server-side solution (coldfusion), but I bet it could be done
client-side as well, if needed.

--
--
~kaeli~
Condoms should be used on every conceivable occasion.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #8
Lasse Reichstein Nielsen wrote:
<script type="text/javascript" src="file:///C:/mydir/program.js">


The problem is that you need to change the file before uploading
to a server. The advantage is that it works locally :)


The solution is to install and run an httpd on the development PC, then you are
accessing the site using the same protocol and file paths as you will on the
real server.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #9
"Christian Eyrich" <VJ**********@spammotel.com> wrote in message
news:bt************@ID-205057.news.uni-berlin.de...
<snip>
... But on the local machine mydir is searched in the
root dir - wherever this may be on Windows machines
(not C: at least on Win98).

<snip>

If you look at a file protocol URL on a Windows machine, such as -
file:///C:/mydir/program.js
- you may notice that the "file:" part is separated from the rest of
the URL by three slashes instead of the two that would usually be in
that location. The last of those three slashes represents the root
directory and as that is above the level of the drive letter it clearly
cannot represent any real location in the file system of a windows
machine. IE browsers seem to confuse the issue by applying the same path
rules that the OS uses when resolving file names.

Richard.

Jul 20 '05 #10
"Richard Cornford" <Ri*****@litotes.demon.co.uk> writes:
If you look at a file protocol URL on a Windows machine, such as -
file:///C:/mydir/program.js
- you may notice that the "file:" part is separated from the rest of
the URL by three slashes instead of the two that would usually be in
that location. The last of those three slashes represents the root
directory


No. It separates the server from the path. In file URL's the server
can be omitted if it is "localhost", but the above is equivalent to
the URI
file://localhost/C:/mydir/program.js
The usual rules apply, so this can be separated using the grammar
productions (RFC 2396 section 3):

absoluteURI :: scheme ":" hier_part
hier_part :: net_path
net_path :: "//" authority [abs_path]
abs_path :: "/" path_segments

Here, scheme is "file", authority is the "localhost" server and
path_segments is "C:/mydir/program.js".

There is no initial slash in the path segments, but when the
scheme+server is specified, the path is necessarily absolute.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #11
JRS: In article <hd**********@hotpop.com>, seen in
news:comp.lang.javascript, Lasse Reichstein Nielsen <lr*@hotpop.com>
posted at Fri, 2 Jan 2004 19:02:57 :-

function makeMyImg() {
var img = new Image();
img.src = "../images/myImage.png";
return img;
}

The problem is that when that code is called from an HTML page, the path
is taken relative to the HTML file, not the Javascript file. If you have
HTML files in different levels of directories, no relative path will
work for all of them. That makes absolute paths necessary for Javascript
files that are shared between different pages.

When a page is being written, one should know its position on the site.

So surely the function should be along the lines of

function makeMyImg(PartPath) {
var img = new Image();
img.src = PartPath + "images/myImage.png";
return img;
}

or even have the full name of the image passed as a parameter?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #12
Lasse Reichstein Nielsen wrote:
The problem is that when that code is called from an HTML page, the path
is taken relative to the HTML file, not the Javascript file. If you have
HTML files in different levels of directories, no relative path will
work for all of them. That makes absolute paths necessary for Javascript
files that are shared between different pages.


It does not. In the linked script file you can retrieve the URL of
the linking document, as for example (from my box of olde things ;-)):

function CalcPaths() { /* Calculates relative image file paths to
absolute ones */
var PathEnd = document.URL.lastIndexOf('\\'); // Folder path
if (PathEnd == -1)
PathEnd = document.URL.lastIndexOf('/'); // URL
if (PathEnd == -1) { // Extends filename to full path
var prevImgCollapsed = imgCollapsed;
imgCollapsed = document.URL.slice(0, PathEnd);
imgCollapsed += "/";
imgCollapsed += prevImgCollapsed;
var prevImgExpanded = imgExpanded;
imgExpanded = document.URL.slice(0, PathEnd);
imgExpanded += "/";
imgExpanded += prevImgExpanded;
}
}
PointedEars
Jul 20 '05 #13
On Fri, 2 Jan 2004 06:11:14 -0800 (PST),
wylbur37 <wy************@yahoo.com> wrote:
(This is a re-post of something that apparently did not post correctly
the first time, so if there's more than one copy, please ignore the
duplicate).

I normally use Mozilla 1.4 on Windows XP Pro.
As I was developing some test webpages, I discovered that the SRC
parameter doesn't seem to work when a path is used with the filename.

In one example, when I want to run a JavaScript from an external file
(i.e., not inline), I would do the following ...

<SCRIPT LANGUAGE="JavaScript" SRC="program.js"> </SCRIPT>

If "program.js" were in a different subdirectory than the .htm file
referring to it, the filename would have to be prefixed by the
pathname as follows ...

<SCRIPT LANGUAGE="JavaScript" SRC="/mydir/program.js"> </SCRIPT>


Try

<SCRIPT LANGUAGE="JavaScript" SRC="file:///mydir/program.js">
</SCRIPT>

or

<SCRIPT LANGUAGE="JavaScript"
SRC="http://my.server.org/mydir/program.js">
</SCRIPT>

AFAIK, you don't assume a server. Just because it works in IE, doesn't
make it correct. And don't use backslashes, IE might not balk at them,
but if you ever want to view the files in anything but IE, you'll be
disappointed.

HTH,

Michael C.
--
mc******@usol.com http://mcsuper5.freeshell.org/

If we cease to judge this world, we may find ourselves, very quickly, in
one which is infinitely worse. - Margaret Atwood
Jul 23 '05 #14

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

Similar topics

2
by: wylbur37 | last post by:
I normally use Mozilla 1.4 on Windows XP Pro. As I was developing some test webpages, I discovered that the SRC parameter doesn't seem to work when a path is used with the filename. In one...
2
by: Randell D. | last post by:
HELP! Its taken me ages - I'm a newbie and I've compiled bits of code that I've read in this newsgroup over time to create one of my most intricate functions to date... Basically, the script...
2
by: schieco | last post by:
The following code always prints the debug lines inside the conditional if statement before and after the alert statement when the session has timed out, but the alert and redirect only appear/work...
6
by: Mark Olbert | last post by:
The doPostBack javascript functioning is not submitting the page when called by linkbuttons (or an autopostback checkbox, for that matter). I'm aware of a problem with Netscape browsers and the...
3
by: JohnnyGr | last post by:
I have heard theres a new way to start threads with parameters in framework 2.0, does anyone know how to do that? this is what i need to do... Start a thread that executes some stuff, in this...
1
by: logik3x | last post by:
I'm developping a program to automate the submisson of grades to a website called omnivox.ca (http://brebeuf.omnivox.ca). My problem is that I can't get the login working. I get the cookie right...
4
by: =?Utf-8?B?QmlsbEF0V29yaw==?= | last post by:
Hi, We recently converted a 1.1 project to 2.0 and this included a webservice which accepted XML for one of the parameters. Since converting to 2.0 I am getting the following message: --- A...
3
by: pmadhu512 | last post by:
hi below code is working in the IE6 and mozilla but not working IE7.when i moving the mouse to the block the popup getting closed could you please help me how to resolve this problem ...
3
by: Sarah | last post by:
I was wondering if someone might be able to help me with this issue. I have a feeling this has something to do with my host's server settings as I used to be able to get CURL to follow redirects by...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.