英文: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

test page

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

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:php中文网

链接在HTML的英文,英文:A链接标记ie下会自动补全href_HTML/Xhtml_网页制作相关推荐

  1. 英文输入时的自动补全功能

    以搜狗输入法为例,在中文输入状态下,右击搜狗自定义状态栏,将"英文输入(E)"点亮,即可实现英文输入的自动补全

  2. linux拷贝到新建文件夹命令行,Linux创建文件touch,复制文件cp,tab补全,链接文件ln命令...

    一.创建文件 使用touch 可以创建空文件,例如opt目录下创建test2.txt文件.这种一般是有些程序必须要先创建文件,才能使用. 二. 复制文件 2.1 使用cp命令来复制文件,需要两个参数- ...

  3. Linux入门学习(四)—— 什么链接文件?软链接文件和硬链接文件有什么区别以及特点?

    引言:上期回顾(想要学习的童鞋可以点击看看) 前几章我们所说的命令都是针对文件和文件夹,和一些常用操作.今天我们来学习特殊一点的文件"链接文件",这一章节会告诉大家什么是链接文件, ...

  4. linux文件系统的链接,用户指南:Linux文件系统的链接

    total 16 -rw-rw-r-- 3 dboth dboth 7 Jun 13 07:34 link1.file.txt -rw-rw-r-- 3 dboth dboth 7 Jun 13 07 ...

  5. html链接文件不可用,PPT2013如何解决链接文件失效

    工作中在做PPT时,经常需要添加一些视频或音频之类的链接文件.而我们拷贝到另外一台电脑上的时候,由于这些链接文件的路径变了,这些链接也就失效了.遇到链接失效怎么办?下面学习啦给大家分享解决链接失效的方 ...

  6. 在html中怎么制作友情链接,如何制作一个网页链接,用描文本、友情链接交易方式教你如何制作?...

    如何制作一个网页链接,用描文本.友情链接交易方式教你如何制作?作为seo优化人员如何运用外界链接开展百度搜索引擎提升?下面和小编一起看看! 1.锚点链接链接应该是有关的 优先,百度搜索引擎提升锚点链接 ...

  7. 查询链接服务器信息,如何通过 SQL Server 链接服务器和分布式查询使用 Excel

    作为链接服务器查询 Excel 您可以使用企业管理器.系统存储过程或 SQL-DMO(分布式管理对象)将 Excel 数据源配置为 SQL Server 链接服务器.在所有的这些情况中,您总需要设置以 ...

  8. onenote快捷键_onenote链接系列:链接笔记如何产生?与插入链接的区别

    上一篇中,已经详细介绍了链接笔记的定义.本文对链接笔记的相关注意事项进行进一步总结,并分析链接笔记与普通的插入链接的区别. 1 几点注意事项 一.停靠状态下,手动键入和复制粘贴,两种方式形成的链接笔记 ...

  9. libcurl linux 静态链接库_GCC 程序编译的静态链接和动态链接

    转自:Mr_Bluyee 在链接阶段中,所有对应于源文件的 .o 文件."-l" 选项指定的库文件.无法识别的文件名(包括指定的.o目标文件和.a库文件)按命令行中的顺序传递给链接 ...

最新文章

  1. C# 中 以 # 打头的 编码 是: html 编码解码地址 转换
  2. 一道有关球赛队员分配的C++程序题目
  3. 服务器中使用Com组建处理Excel 常见问题
  4. Android应用程序获得root权限
  5. 微软面试题:鸡蛋从第N层及以上的楼层落下会摔破
  6. 纯真IP数据库的应用!
  7. python3标准库书怎么样_Python3标准库:filecmp比较文件
  8. Qt学习笔记之样式表
  9. macos可以升级到指定版本吗_承装承修承试可以跨级升级吗?
  10. 04 循环结构概述和for语句的格式及其使用
  11. 刷卡读取信息自动录入表格_人事自动化管理系统.xls
  12. Html 中表单提交的一些知识总结——防止表单自动提交,以及submit和button提交表单的区别...
  13. hdu Robberies
  14. 七雄争霸mysql修改_七雄争霸单机版游戏
  15. 上海大华条码称代码_上海大华条码秤简易说明书
  16. AWS、Azure等国外云计算如何迁移到国内阿里云上?
  17. android 自定义圆点,Android自定义带圆点的半圆形进度条
  18. 怎么找回xmind意外关机的文件_Xmind 导图保存丢失怎么找回?
  19. Android 中的自定义 Snackbar
  20. 连接手表_用EMUI11连接华为手机与手表 出门不用全程盯着手机

热门文章

  1. Lodash 中文文档 (v3.10.1) - “Number” 方法
  2. PHP ThinkPHP学习第一步(搭建及认识ThinkPHP入口文件)
  3. 在两个有序的数组中找第N个数,二分查找 O(lgm+lgn)级
  4. VS2010小Bug:找不到System.Web.Extensions.dll引用
  5. Linux下c开发 之 线程通信与pthread_cond_wait()的使用
  6. python 线程超时设置_python 条件变量Condition(36)
  7. 51单片机C语言led流水灯及数码管实现秒表
  8. Java编程中值得注意的对象引用现象
  9. 步步为营-77-Ajax简介
  10. 后台寻路系统的大体思路与流程