国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 中山市| 杭州市| 桂林市| 儋州市| 蓬莱市| 应城市| 信丰县| 泰兴市| 岑溪市| 会泽县| 高清| 启东市| 长宁县| 蒲江县| 九寨沟县| 彰化县| 阿尔山市| 沾益县| 汾西县| 伊宁县| 开平市| 邵阳市| 江源县| 固原市| 四会市| 灵石县| 临桂县| 乌恰县| 济源市| 普兰店市| 伊吾县| 陵水| 新绛县| 壶关县| 桂阳县| 岳阳县| 禹城市| 安福县| 涞源县| 黔江区| 鞍山市|