英文:A链接标记ie下会自动补全href

所属分类: 网页制作 / HTML/Xhtml 阅读数: 330
收藏 0 赞 0 分享

英文:A链接标记ie下会自动补全href.
Whilst working on the Ajax Link Tracker and MapSurface I have come across an inconsistency in how the href attribute is retrieved using DOM Scripting.
The href attribute is different to other element attributes in that the value set can be relative to the context of the page URL. If you set a link with a relative href attribute
<a href="../development/test1.html">test page</a>
The browser will look at the pages current URL and derive an absolute URL for the link.
http://www.glenn.jones.net/development/test1.html
This is the root of the problem, some browsers return the text of the attribute and others return the derived absolute URL. The results also differ by the method you use to retrieve the href attribute. There are three common ways to access an attribute:
linkobj.href; linkobj[‘href’]; linkobj.getAttribute(‘href’);
The linkobj.href and linkobj[‘href’]; methods of accessing the attribute consistently return the derived absolute URL.
Microsoft has tried to address this by problem adding a second parameter to the getAttribute method. The second parameter can be set to 0,1 or 2. If the parameter is set to 2 the method returns the attribute text. Any other setting will return the derived absolute URL.
linkobj.getAttribute(‘href’); linkobj.getAttribute(‘href’,2); Derived
Absolute URL Attribute Text IE linkobj.href; x IE linkobj.getAttribute(‘href’); x IE linkobj.getAttribute(‘href’,2); x Gecko linkobj.href; x Gecko linkobj.getAttribute(‘href’); x Gecko linkobj.getAttribute(‘href’,2); x Opera linkobj.href; x Opera linkobj.getAttribute(‘href’); x Opera linkobj.getAttribute(‘href’,2); x Get attribute test page Test on IE6, Firefox 1.5 and Opera 8.51.
So what should be returned by the getAttribute method? The W3C DOM Level 2 Core specification which sets out the structure of the getAttribute method does not cover this issue. It is not that either approach is wrong or right. On this point the specification is open to interpretation.
As a coder I would like to be able to access both values. The DOM Core specification should be updated to address the problem.
After a really good exchange with Jim in the comments below, I stand corrected. The specification does say the getAttribute should return the attribute value, not the absolute URL. The Microsoft approach is wrong.
For the time being I am using the old school object property method linkobj.href to return derived absolute URLs. It provides the most consistent results across all browsers. URLs of interest
W3C REC DOM Level 2 Core specification for getAttribute
Gecko documentation for getAttribute
Microsoft documentation for getAttribute
As usual just as I was finishing this post I found this bug report on the QuickMode site which discusses the same subject.
getAttribute HREF is always absolute.html
更多精彩内容其他人还在看

被遗忘掉的button标签

注:这篇文章已经有人翻译过重新认识button 标签,但是感觉其中有很多地方值得推敲,不太好理解。因此本人结合个人学习体会重新翻译而成此文。 英文原文:http://particletree.com/features/rediscovering-the-button-elemen
收藏 0 赞 0 分享

标记语言——标题

点击这里返回网页教学网 HTML教程 栏目. 上文:Chapter1 清单 原文出处 标准化设计解决方案 - 标记语言和样式手册 Web Standards Solutions The Markup and Style Handbook Part 1:
收藏 0 赞 0 分享

改进网站设计提供的有意的建议

科学设计你的网站网页:来自 Eye-Tracking研究的23节必修课——Christina Laun 在网络设计领域关于Eye-Tracking的研究十分火爆,但是如何把这些研究结果转变为具体可行的设计来运作依旧是个难点。以下就是一些来自于Eye-
收藏 0 赞 0 分享

网页教案,针对初学者的教案

教学主题 网页 适用年级
收藏 0 赞 0 分享

多个HTML页面共同调用一段html代码的方法

这篇文章主要介绍了多个HTML页面共同调用一段html代码的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

提交表单后转到另一个文件

问题:在HTML中如何写跳转到某文件? HTML中我希望按了提交后转到aaa.asp这个文件,action这里应该怎么写? form<form id="form" name="form" method="post
收藏 0 赞 0 分享

表格标签(table)深入了解

表格(table)是一直以来长期被大家使用的标签,直到现在还是在用,不过呢因为现在的网站重构,建议大家不要表格(table)来布局而很多朋友误以为用表格(table)就是所谓的不标准了,其实不然,表格(table)是一个重要元素。 前不久为了寻找表格(table)所包含的主
收藏 0 赞 0 分享

容易混淆使用位置的XHTML标签

  我们在webjx.com的文章中一直在强调语义,那么对于HTML标签该如何使用呢?他们一般的使用位置在哪里呢?   在刚接触XHTML CSS设计网页时,对于标签的使用没什么经验,也很随意,经常是想起什么就用什么,认为只要能实现效果就可以。但随着学习的深入和对搜索引擎优
收藏 0 赞 0 分享

类型File的Input按钮功能研究

在一些网站进行上传时,当单击了“浏览”按钮之后会弹出【选择文件】的对话框。很多时候我们需要只上传图像文件,那么在弹出的【选择文件】对话框中只显示了相关图片格式的文件,此外其余格式文件一律过滤不被显示。 比如 http://www.youku.com/
收藏 0 赞 0 分享

ul列表标记设计网页多列布局

几天在用CSS写三列布局的时候突然想到的这样一个方法,这个想法自己都觉得有些疯狂,如果其中有什么不对的地方请各位不吝指教。   当需要写一个三列布局的时候,一般情况下我会选择使用如下的DIV布局方式:
收藏 0 赞 0 分享
查看更多