为什么不MSHTML的净有querySelector和querySelectorAll,或者他们在哪里?MSHTML、querySelector、querySelectorAll

由网友(效仿余生)分享简介:我想用MSHTML [1]访问DOM在IE浏览器,但我刚刚发现,它缺乏querySelector和querySelectorAll方法在HTML文档类,否则将有很大的帮助,以获得通过CSS选择一个文档中的元素I want to use MSHTML [1] to access DOM in IE, but I hav...

我想用MSHTML [1]访问DOM在IE浏览器,但我刚刚发现,它缺乏querySelector和querySelectorAll方法在HTML文档类,否则将有很大的帮助,以获得通过CSS选择一个文档中的元素

I want to use MSHTML [1] to access DOM in IE, but I have just found out that it lacks querySelector and querySelectorAll methods in HTML document classes, which will otherwise be very helpful to obtain elements within a document by CSS selectors.

唯一的解决办法我能想到的,现在是通过执行一个脚本做的一切,但它是可怕的。

The only workaround I can think of for now is to do everything by executing a script, but it is awful.

有没有,有两种方法(querySelector和querySelectorAll)任何MSHTML的版本?是否有任何其他库(希望,通过微软官方.NET库),其中两种方法或者其等效可用?

Is there any MSHTML version that has the two methods (querySelector and querySelectorAll)? Is there any other libraries (hopefully, official .Net libraries by Microsoft) where the two methods or their equivalents are available?

[1]的%ProgramFiles(x86)的% Microsoft.NET 主互操作程序集 Microsoft.mshtml.dll

[1] %ProgramFiles(x86)%Microsoft.NETPrimary Interop AssembliesMicrosoft.mshtml.dll

推荐答案

在querySelector()方法和朋友都活的很好的MSHTML和IE浏览器的DOM,问题是,PIA,大多数程序员对他们的机器严重已经过时。在GAC注册我的机器上一个带有7.0.3300.0版本号,可以追溯到2002年。

The querySelector() method and friends are alive and well in MSHtml and the IE DOM, the problem is that the PIA that most programmers have on their machine is heavily outdated. The one registered in the GAC on my machine carries a 7.0.3300.0 version number, that dates back to 2002.

有一个解决方法,你可以生成自己的互操作库,避免了一个在GAC。关键是要通过不强名称创建一个互操作程序集,因此不能在一个在GAC匹配故意产生不匹配。一定要做到这一点只在VS2010或更高版本,你要采取的嵌入互操作类型的要素优势。

There is a workaround for that, you can generate your own interop library and avoid the one in the GAC. The trick is to intentionally generate a mismatch by creating an interop assembly without a strong name so it cannot match the one in the GAC. Be sure to do this only on VS2010 or later, you want to take advantage of the Embed Interop Types feature.

启动Visual Studio命令提示符,然后定位到您的项目目录。并执行以下命令:

Start the Visual Studio Command Prompt and navigate to your project directory. And execute this command:

  Tlbimp c:windowssystem32mshtml.tlb

这将滚一会儿,类型库大,吐出几个恶心找警告,可以忽略。回到VS,删除现有MSHTML参考,并使用添加引用,浏览选项卡。选择由TLBIMP生成的Mshtml.dll文件。

It will trundle for a while, the type library is big, and spit out several icky looking warnings that you can ignore. Go back to VS, remove the existing MSHTML reference and use Add Reference, Browse tab. Pick the MSHTML.dll file that was generated by Tlbimp.

我不能保证有没有任何问题,你需要保持你的用户需要有IE浏览器的一个上最新版本的头脑,preferably一个值匹配你的。如果在接口上使用的方法,IE浏览器的旧版本不具备那么它将nastily失败pretty的,一个AccessViolationException是可能的。

I cannot guarantee having no problems at all, you do need to keep in mind that your user needs to have an up-to-date version of IE, preferably one that matches yours. If you use a method on an interface that an older version of IE doesn't have then it will fail pretty nastily, an AccessViolationException is likely.

阅读全文

相关推荐

最新文章