相对网址:可以省略“http:”? [英] relative URLs: OK to omit "http:"?

查看:89
本文介绍了相对网址:可以省略“http:”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在进行网络搜索后,似乎可以省略http:形成

相对URL。这有什么陷阱吗?


例如,如果有页面
http://www.domain1.com/page1.html

链接指向
http://www.domain2.com/page2.html

you可以将第二个链接缩写为

//www.domain2.com/page2.html


我想知道的是,如果有任何缺点可以这个。 (我可以想到的是,如果有人将HTML页面保存到他们的硬盘上,那么链接

将不再起作用,因为URL是相对的这个文件在

网站上,而不是在他们的硬盘上。)


另外,我只是尝试了它,似乎点击后的链接页面

已保存到硬盘驱动器崩溃IE 6.0。

After doing a websearch, it appears that it''s OK to omit the "http:" to form
a relative URL. Are there any pitfalls to this?

For example, if there is a page
http://www.domain1.com/page1.html
with a link to
http://www.domain2.com/page2.html
you can abbreviate the second link as
//www.domain2.com/page2.html

What I''m wondering is if there are any drawbacks to this. (One that I can
think of is that if someone saves the HTML page to their hard disk, the link
won''t work anymore since the URL is relative to the document as on the
website, not as on their harddrive.)

Also, I just tried it and it seems that clicking on the link after the page
has been saved to the hard drive crashes IE 6.0.


推荐答案

险恶写道:
在进行网络搜索后,似乎可以省略http:形成一个相对的URL。这有什么陷阱吗?
After doing a websearch, it appears that it''s OK to omit the "http:" to form
a relative URL. Are there any pitfalls to this?



href属性使用不正确:

< http://www.w3.org/TR /REC-html40/struct/links.html#h-12.>它应该

包含一个URI:< http://www.w3.org/TR/REC-html40/types.html#type-uri>


你的例子是_not_一个有效的URI。

-

Anne van Kesteren
http://www.annevankesteren.nl/


" sinister < SI ****** @ nospam.invalid>写道:
"sinister" <si******@nospam.invalid> wrote:
在进行网络搜索后,似乎可以省略http:形成一个相对的URL。


当然,这是创作几乎所有网站的基本部分。

这有什么陷阱吗?


如果您在网站内移动文件,则需要更改链接。

例如,如果有页面
http://www.domain1.com/page1.html
链接到
http://www.domain2.com/page2.html
你可以将第二个链接缩写为
//www.domain2.com/page2.html


不,你会把它缩短为只是page2.html或/page2.html

您提供的版本非常奇怪,可能会导致问题。

我想知道的是,如果有任何缺点这个。 (我可以想到的一个问题是,如果有人将HTML页面保存到他们的硬盘上,那么该链接将不再起作用,因为该URL与文档相关,如同
网站,而不是他们的硬盘。)


这是真的。但浏览器可能会在将文件保存到

命令时更改该文件以防止这种情况发生。浏览器各不相同,你如何触发这个

的行为也可能会有所不同。

另外,我只是尝试了它,似乎点击页面后面的链接已保存到硬盘驱动器崩溃IE 6.0。
After doing a websearch, it appears that it''s OK to omit the "http:" to form
a relative URL.
Of course, it''s a basic part of authoring almost any site.
Are there any pitfalls to this?
You need to change links if you move a file around within a site.
For example, if there is a page
http://www.domain1.com/page1.html
with a link to
http://www.domain2.com/page2.html
you can abbreviate the second link as
//www.domain2.com/page2.html
No, you''d shorten it to just page2.html or /page2.html
The version you give is very odd and might cause problems.
What I''m wondering is if there are any drawbacks to this. (One that I can
think of is that if someone saves the HTML page to their hard disk, the link
won''t work anymore since the URL is relative to the document as on the
website, not as on their harddrive.)
That''s true. But the browser may alter the file when it saves it in
order to prevent this. Browsers vary, and how you trigger this
behaviour may vary as well.
Also, I just tried it and it seems that clicking on the link after the page
has been saved to the hard drive crashes IE 6.0.




嗯。使用上面引用的奇怪网址?并不感到惊讶,因为它不会起作用,因为它实际上会崩溃。但是我们在这里谈论IE浏览器...


史蒂夫


-

我的理论给你起见,我的异端邪说你愤怒,

我从不回信,你不喜欢我的领带。 - 医生


Steve Pugh< st *** @ pugh.net> < http://steve.pugh.net/>



Hmmm. Using the strange URL you quoted above? Not surprised that it
doesn''t work, surprised that it actuallu crashes anything. But we are
talking IE here...

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don''t like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>




" sinister" < SI ****** @ nospam.invalid>在消息中写道

新闻:DR *************** @ nwrddc01.gnilink.net ...

"sinister" <si******@nospam.invalid> wrote in message
news:DR***************@nwrddc01.gnilink.net...
做了网络搜索,似乎可以省略http:到
形成一个相对URL。这有什么陷阱吗?

例如,如果有一个页面
http://www.domain1.com/page1.html
带有链接
http://www.domain2.com/page2.html
您可以将第二个链接缩写为
// www.domain2.com/page2.html
After doing a websearch, it appears that it''s OK to omit the "http:" to form a relative URL. Are there any pitfalls to this?

For example, if there is a page
http://www.domain1.com/page1.html
with a link to
http://www.domain2.com/page2.html
you can abbreviate the second link as
//www.domain2.com/page2.html




这不是相对的。它显示与第一页没有任何关系,

在一个不同的,不相关的网站上。它是一个绝对的URL,没有

的http:。也许某些浏览器假定默认协议为http:。如果你

不要用一个。 IE会在浏览器的

地址字段中省略协议。我不知道如果这样的网址在HREF中的网址是好的,那么IE是否能正常工作。


相对网址只是 - 识别页面'

与当前页面位置关系的位置。如果在page1.html上使用,


page2.html的页面


是对a的引用名为page2.html的文件与

page1.html在同一目录中。引用


../page3.html


指向第一页'目录'的父目录中的页面。一个

参考


/page4.html


指向与第一个服务器相同的服务器上的页面页。这些都是

亲戚。



This isn''t relative. It shows no relationship of any kind to the first page,
which is on a different, unrelated web site. It is an absolute URL without
the "http:". Maybe some browsers assume a default protocol of "http:" if you
don''t use one. IE does if you leave out the protocol in the browser''s
Address field; I don''t know if IE will work properly if a URL like this is
in an HREF.

A relative URL is just that--identification of a page''s location in
relationship to the location of the current page. If used on page1.html, a
URL of

page2.html

is a reference to a file called page2.html in the same directory as
page1.html. A reference to

../page3.html

points to a page in the first page''s directory''s parent directory. A
reference to

/page4.html

points to a page on the same server as the first page. These are all
relative.


这篇关于相对网址:可以省略“http:”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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