国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

英文:A鏈接標記ie下會自動補全href

2024-08-26 00:09:20
字體:
供稿:網(wǎng)友

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
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 宜川县| 和政县| 隆子县| 上犹县| 鹤壁市| 青田县| 古浪县| 南投市| 芜湖市| 洛宁县| 岳阳市| 蓬溪县| 积石山| 安多县| 荔波县| 三台县| 西华县| 黄浦区| 龙州县| 溧阳市| 济阳县| 天柱县| 大田县| 雷山县| 渭源县| 珲春市| 佛冈县| 尼木县| 曲麻莱县| 永年县| 天长市| 通化县| 盖州市| 丰镇市| 朝阳区| 重庆市| 惠东县| 富平县| 行唐县| 陈巴尔虎旗| 中西区|