gpt4 book ai didi

html - 使用 HTML 字符串生成默认浏览器

转载 作者:行者123 更新时间:2023-12-04 13:24:06 24 4
gpt4 key购买 nike

我有代码(和几十年):

  • 给定一些 HTML string内存中
  • 将该文档交给 Internet Explorer 对象
  • 并使 Internet Explorer(单独的进程)可见
  • 所有这些都不会在用户的计算机上放置临时文件

  • 换句话说:
    void SpawnIEWithSource(string szSourceHTML)
    {
    IWebBrowser ie = (IWebBrowser)CoCreateInstance(CLASS_InternetExplorer, null, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
    UuidOf(IUnknown));

    ie.Navigate2("about:blank");
    ie.Document.Write(szSourceHtml);
    ie.Document.Close;
    ie.Visible = True;
    }
  • 优点 :
  • opens an HTML report out of process
  • does not create a temporary file

  • 缺点 :
  • 硬编码 Internet Explorer 的使用,而不是用户首选的浏览器


  • 但是 IE 正在消失
    微软 recently announced Internet Explorer(产品)将不再随 Windows 一起提供,但 Internet Explorer(编程 api)将继续工作:

    As announced today, Microsoft Edge with IE mode is officially replacing the Internet Explorer 11 desktop application on Windows 10. As a result, the Internet Explorer 11 desktop application will go out of support and be retired on June 15, 2022 for certain versions of Windows 10.

    Out of scope at the time of this announcement (unaffected):

    • Internet Explorer mode in Microsoft Edge
    • Internet Explorer platform (MSHTML/Trident), including WebOC
    • Internet Explorer 11 desktop application on:
      • Windows 8.1
      • Windows 7 Extended Security Updates (ESU)
      • Windows 10 Server SAC (all versions)
      • Windows 10 IoT Long-Term Servicing Channel (LTSC) (all versions)
      • Windows 10 Server LTSC (all versions)
      • Windows 10 client LTSC (all versions)

    What is the MSHTML (Trident) engine? How does that relate to IE mode?

    The MSHTML (Trident) engine is the underlying platform for Internet Explorer 11. This is the same engine used by IE mode and it will continue to be supported (in other words, unaffected by this announcement). WebOC will also continue to be supported. If you have a custom or third-party app that relies on the MSHTML platform, you can expect it to continue to work.


    (强调我的)
    这意味着微软正在打破 23 年的向后兼容性——并用……什么都没有。
    所以我需要找到一种方法来替换它。
  • 生成默认浏览器
  • 给它 HTML 我想显示
  • 所有没有临时文件

  • 奖励阅读
  • .NET: How to make WebBrowser control launch in IE, display HTML, out of process?
  • How to put the WebBrowser control into IE9 into standards?
  • How to start browser with html string with lua
  • Creating an IWebBrowser2 control
  • 最佳答案

    我会将 HTML 编码为 Base64 and make it a Data-URI .所有现代浏览器都能够处理此类 URI。但是,如果您的 HTML 字符串太大,这将不起作用。
    基本上,它会是这样的:

    string Base64Encode(string plainText) {
    var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
    return System.Convert.ToBase64String(plainTextBytes);
    }

    void SpawnBrowserWithSource(string szSourceHTML) {
    System.Diagnostics.Process.Start("data:text/html;base64," + Base64Encode(szSourceHTML));
    }
    (代码片段来自以下 Stackoverflow 答案: base64 encodingopening default browser )

    关于html - 使用 HTML 字符串生成默认浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69729093/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com