包含路径时,SRC参数在Mozilla中不起作用 [英] SRC parameter not working in Mozilla when path is included

查看:56
本文介绍了包含路径时,SRC参数在Mozilla中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(这是第一次显然没有正确发布的东西的重新发布

,所以如果有多个副本,请忽略

重复)。


我通常在Windows XP专业版上使用Mozilla 1.4。

当我开发一些测试网页时,我发现了SRC 参数似乎不起作用。


在一个示例中,当我想从外部文件运行JavaScript时

(即不是内联),我会做以下事情......


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


如果program.js与.htm文件不同的子目录

引用它,文件名必须以

路径名为前缀,如下所示......


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


但是当我从本地加载的.htm文件中运行上面的内容到

Mozilla时,它没有用。 (结果好像上面的代码不是那么的b $ b)。但是,当我在Internet Explorer上运行相同的代码

(v.6)时,它工作正常。

在另一个,甚至更简单的例子中,放置图像的代码一个

的网页是...


< img src =" picture.jpg">


同样,如果picture.jpg与引用它的.htm

文件位于不同的子目录中,则文件名必须以

路径名为前缀为跟随...


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


当我从上面运行以上内容时在.htm文件本地加载到

Mozilla中,它没有用。 (结果好像上面的代码不是那么的b $ b)。但是,当我在Internet Explorer上运行相同的代码

(v.6)时,它工作正常。

顺便说一下,我尝试使用反斜杠而不是正斜杠。在

两种情况下,它仍然适用于Internet Explorer但不适用于Mozilla。

SRC参数似乎是一个相当常用的参数

Mozilla的开发人员忽略了它。这真的是一个错误吗?

Mozilla或者它只是Mozilla中的一些选项/开关,我没有设置

正确吗?

__________________________________

你是雅虎吗??

了解什么是顶级雅虎! 2003年的搜索
http://search.yahoo.com/top2003

(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

推荐答案

wylbur37说:
wylbur37 said:
SRC参数似乎是
Mozilla的开发人员忽视它。这真的是Mozilla中的一个错误,还是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?




两者都没有。


以/开头的网址是无效的。由于当前页面的URL与

无关,因此必须指定协议。 IE允许

你逃脱它,假设你的意思是文件:协议。


有很多原因导致浏览器做出这样的假设是不好的,但是它们的平衡因为接受糟糕的

代码会欺骗一些人认为其他浏览器

都是错误的,因此他们不太可能支持他们,给予

更宽松的浏览器具有市场优势。


正确的标签是:


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


当你打开任何
$时,你应该在位置栏中看到这种格式b $ b本地HTML文件。



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.


Lee< RE ************** @ cox.net>写道:
Lee <RE**************@cox.net> writes:
以/开头的网址是无效的。由于它与当前页面的URL无关,因此必须指定协议。如果你的意思是文件:,IE会让你侥幸成功。协议。


一般情况下无效。作为URI片段,它定义了相对于当前协议和服务器的

绝对路径。对于IE来说,假设文件是正确的,这是正确的。协议和localhost

服务器。它变得冒险的地方是本地文件发生的事情。


如果本地文件的URL是

file:// localhost / c:/ somedire / myhtml / foo.html

然后在该上下文中使用URI片段/mydir/program.js"应该



文件://localhost/mydir/program.js

这很可能不是想要的。首先,它不包括

一封驱动器号。我想这就是Mozilla所做的(好吧,让我检查......是的,

它给出了

file:///mydir/program.js

等价 - 在文件协议中省略服务器名称意味着

服务器是localhost。)


如果你将它与IE进行比较,相同的测试给出:

file:/// D:/mydir/program.js

(我的测试文件在D:驱动器上)。根据

的定义,这是不正确的,但显然在基于windows的

机器上工作得更好。


Mozilla也运行在例如Unix机器上,那里没有驱动器

字母,所以我可以看到为什么要保持代码一般。

有很多原因为什么它'对于浏览器做出那种假设是不好的,但是他们通过接受糟糕的代码会欺骗一些人认为其他浏览器是错误的这一事实来平衡,并且所以他们不太可能支持他们,让更宽松的浏览器具有市场优势。


听到,听到!

< script type =" text / javascript" src =" file:/// C:/mydir/program.js">
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">




问题是你需要在上传之前更改文件/>
到服务器。优点是它在本地工作:)


/ L

-

Lasse Reichstein Nielsen - lr*@hotpop.com

DHTML死亡颜色:< URL:http://www.infimum.dk/HTML/rasterTriangleDOM。 html>

''没有判断的信仰只会降低精神神圣。''



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


2004年1月2日07:02:37 -0800, Lee< RE ************** @ cox.net>写道:
On 2 Jan 2004 07:02:37 -0800, Lee <RE**************@cox.net> wrote:
以/开头的网址是无效的。由于它与当前页面的URL无关,因此必须指定协议。如果你的意思是文件:,IE会让你侥幸成功。 protocol。
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.




只要文档有基本URL,该语句就不正确;

显式指定或从文档派生(它的文件:或http:

URL)。以单个正斜杠开头的URL将被解析为:


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

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


如果''mydir''是''html''中的子目录,相对URL应该是:


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


或者:


rel:mydir / picture。 jpeg


你说的是正确的,但以正斜杠开头的URL不是

亲戚。


使用文件:scheme,结果应该类似:单个斜杠

将从当前驱动器的根目录开始。但是,RFC

1808并没有给出文件:scheme的例子(可能是因为有很多

和不同的文件系统格式)。


< snip>


Mike

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


在文档末尾有一个示例列表

(第5.1节 - 正常示例),其中包含一个单一的,初始的

正斜杠。


-

Michael Winter
M。****** @ blueyonder.co.inva 盖子(将.invalid替换为.uk以回复)



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)


这篇关于包含路径时,SRC参数在Mozilla中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆