本文介绍了使用IHTMLElement5 / 6(对于IE8 / 9)在IE6 / 7时,会发生什么?是否转向到IHTMLElement行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,IHTMLElement5和IHTMLElement6是主要IHTMLElement按以下规则版本所有扩展接口:

Basically, IHTMLElement5 and IHTMLElement6 are all extended interfaces for the main IHTMLElement as per the versioning rules below:

IHTMLElement    IE4
IHTMLElement2   IE5
IHTMLElement3   IE5.5
IHTMLElement4   IE6
IHTMLElement5   IE8
IHTMLElement6   IE9

当然,每一个新的扩展接口有老队员在里面+自己的新成员,属性等。然而,一些成员(例如,.getAttribute)都是一样的名字,但已被更新。所以,我的问题是,如果我用(说)IHTMLElement6申报我的HTML元素只运行已安装了IE6客户端上的code,什么时候我的目标只是失败,并保留为空/ Nothing后,我将它设置,或者是Mshtml.dll的明智地意识到怎么回事,默认​​为IHTMLElement4(实际上,IHTMLElement)的行为?

Of course, each new extended interface has the old members in it + its own new members, properties etc. However, some of the members (for instance, .getAttribute) are the same name but have been updated. So, my question is, if I use (say) IHTMLElement6 to declare my HTML Element and run the code on a client that only has IE6 installed, when will my object just fail and remain as Null/Nothing when I set it, or is mshtml.dll smart enough to realize whats going on and defaults to IHTMLElement4 (actually, IHTMLElement) behaviour?

只是为了澄清括号内的最后一条语句,.getAttribute在IHTMLElement加入,并在IHTMLElement5和IHTMLElement6更新 - 所以,如果有人只安装了IE6,那么我期望的行为违约/恢复到IHTMLElement(不IHTMLElement4 ) - 如果不这样做,那么我希望我的code崩溃。基本上,我的问题是,究竟会发生什么?

Just to clarify the last statement in brackets, .getAttribute was added in IHTMLElement and updated in IHTMLElement5 and IHTMLElement6 - so, if someone has IE6 installed only, then I would expect the behaviour to default/revert back to IHTMLElement (not IHTMLElement4) - and if it does not do that, then I expect my code to crash. Basically, my question is, what will happen exactly?

现在,因为我很害怕像疯了似的,我只是宣布一切,IHTMLElement,任何想法?

Right now, because I am scared like crazy, I just declare everything as IHTMLElement, any ideas?

感谢。

问题(如果你发现有必要,只是一个reclarification对于那些谁需要它读)总结:
基本上,我希望能够宣布一些如IHTMLElement6这样我就可以利用更新的方法具有IHTMLElement和IHTMLElement6(如.getAttribute)之间的相同的名称。通过这种方式,在IE9用户IHTMLElement6的版本.getAttribute将被利用,而在同一时间IHTMLElement的版本.getAttribute将仍然是(说)IE6用户的工作没有打破我的code - 这是地步我问题来的,在/工作中使用,当IHTMLElement6对象,即使它是一个IE9的界面,将.getAttribute踢IHTMLElement的(IE4接口)版本或我会得到一个空引用异常或其他运行时错误?感谢所有。

Summary of Question (read if you find necessary, just a reclarification for those who need it):Basically, I want to be able to declare something as IHTMLElement6 so I can make use of the updated methods which have the same name between IHTMLElement and IHTMLElement6 (such as .getAttribute). This way, on IE9 users IHTMLElement6's version of .getAttribute will be taken advantage of, while at the same time IHTMLElement's version of .getAttribute will still work for (say) IE6 users without breaking my code - this is the point where my question comes in, when using a IHTMLElement6 object, even though it is an IE9 interface, will IHTMLElement's (IE4 interface) version of .getAttribute kick in/work or will I get a null reference exception or other runtime error? Thanks all.

越是回应越好,哪怕是你的意见,你不知道的一个事实,我想鼓励你,而让我们知道还有评论,如果你知道这是一个事实,或者如果它是只是意见/猜等感谢。

The more responses, the better, even if it is your opinion and you don't know as a fact, I would like to encourage you to still comment while letting us know if you know this as a fact or if it is just opinion/guess etc. Thanks.

推荐答案

我怀疑,在旧版本的IE不支持 IHTMLElement6 ,铸造一个DOM元素 IHTMLElement6 将失败与 InvalidCastException的。你不会有机会叫 IHTMLElement6.getAttribute(),因为你将无法获得有效的 IHTMLElement6 在首位的参考。

I suspect that in older versions of IE that don't support IHTMLElement6, casting a DOM element to IHTMLElement6 will fail with an InvalidCastException. You won't get a chance to call IHTMLElement6.getAttribute() because you won't be able to obtain a valid IHTMLElement6 reference in the first place.

如果这是正确的,那么是什么你已经做(使用 IHTMLElement )似乎是正确的行动路线。

If this is correct, then what you're already doing (using IHTMLElement) seems like the correct course of action.

更新:我的怀疑是正确的。我写了一个WinForms应用程序引用自带的IE9中的Mshtml.dll版本。在与IE9的系统,应用程序成功蒙上了< IMG> 元素 IHTMLElement6 。但随着IE8的系统上,同样的转换失败:

UPDATE: My suspicion was correct. I wrote a WinForms app that references the version of mshtml.dll that comes with IE9. On a system with IE9, the app successfully casts an <img> element to IHTMLElement6. But on a system with IE8, the same cast fails:

System.InvalidCastException:无法投类型的COM对象mshtml.HTMLImgClass接口类型mshtml.IHTMLElement6。此操作失败的原因是对IID{305106F8-98B5-11CF-BB82-00AA00BDCE0B}接口的COM组件调用QueryInterface失败,原因是以下错误:不支持此接口(异常来自HRESULT:0x80004002(E_NOINTERFACE))

这篇关于使用IHTMLElement5 / 6(对于IE8 / 9)在IE6 / 7时,会发生什么?是否转向到IHTMLElement行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 11:31