我如何使用Javascript代码阅读Outlook附件

问题描述 投票:-1回答:1

我正在尝试开发一个代码,在该代码中我需要阅读邮件附件并显示结果。通过API,我可以获取邮件和附件的详细信息。附件是一个.html文件。我如何使用JS读取该.html文件。请帮忙。我是JS的新手。

javascript outlook-restapi
1个回答
0
投票

您可以使用Javascript的DOMParser执行此操作。这是解析html文件的代码:

parser = new DOMParser();
doc = parser.parseFromString(stringContainingHTMLSource, "text/html")

希望这会有所帮助

已更新:

根据您的评论,您可以尝试以下代码:

    var htmlstr = "This is the html string we're checking for <a> heartbeat = 77 </70> <h1>exists.</h1>";
    var stringLower = htmlstr.toLowerCase();
    var keyword = "heartbeat = ".toLowerCase(); // Word to look up
    var wordIndex = stringLower.indexOf(keyword);
    if (wordIndex > -1) {
  // get a substring till end of health =
      var subStringIndex = wordIndex + keyword.length;
      var healthData = htmlstr.substring(subStringIndex, subStringIndex+2); //can be +3 too depending on digits or sth gives heartbeat value
      console.log(healthData); //output heartbeat value
    } else {
      console.log("Not found");
    }

希望这会有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.