如何基于正则表达式在 O365 邮件应用程序中加载不同的页面
How to load different pages in O365 mail app based on regex
我正在创建一个 O365 应用程序,我有 2 个.aspx文件,当用户单击 O365 邮件应用程序时,我希望根据邮件的主题加载这些页面中的每一个。
方案 1:邮件主题包含"#"结果:加载页 1
方案 2:邮件主题不包含"#"结果:加载页2
我尝试过有一个中间.js文件,我在其中编写了逻辑,但是当我做 window.location = "path_to_aspx_file"时,仅加载 HTML,但 JS 文件不运行。
我目前的实现:
我有着陆逻辑.js
(function () {
"use strict";
//The Office initialize function must be run each time a new page is loaded
Office.initialize = function (reason) {
$(document).ready(function () {
var item = Office.cast.item.toItemRead(Office.context.mailbox.item);
var sub = item.subject;
if (sub.indexOf("some text") > -1) {
window.location = "http://localhost:51776/File1.aspx";
}
else {
window.location = "http://localhost:51776/File2.aspx";
}
});
};
})();
经过一番摸索。我现在能够导航到这些文件中的每一个,但我不确定如何从 File1.aspx 和 File2.aspx 访问邮件主题。
在使用 Office
JavaScript API 获取主题之前,您是否初始化了 Office 上下文?为了轻松重定向 HTML 页面,我们可以包含如下所示的 JavaScript:
首页.js:
/// <reference path="../App.js" />
(function () {
"use strict";
// The Office initialize function must be run each time a new page is loaded
Office.initialize = function (reason) {
$(document).ready(function () {
app.initialize();
RedirectHTMLPage();
});
};
function RedirectHTMLPage() {
var subject = Office.context.mailbox.item.subject;
if (subject.indexOf("#") != -1) {
window.location.href = "https://localhost:44300/page1.aspx";
} else {
window.location.href = "https://localhost:44300/page2.aspx";
}
}
})();
用于重定向的 HTML 页面:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title></title>
<script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
<link href="../../Content/Office.css" rel="stylesheet" type="text/css" />
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
<!-- To enable offline debugging using a local reference to Office.js, use: -->
<!-- <script src="../../Scripts/Office/MicrosoftAjax.js" type="text/javascript"></script> -->
<!-- <script src="../../Scripts/Office/1/office.js" type="text/javascript"></script> -->
<link href="../App.css" rel="stylesheet" type="text/css" />
<script src="../App.js" type="text/javascript"></script>
<link href="Home.css" rel="stylesheet" type="text/css" />
<script src="Home.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
我尝试过有一个中间.js文件,在那里我写了逻辑,但是当我执行 window.load = "path_to_aspx_file" 时,只加载了 html,但 js 文件不会运行。
您介意分享您使用"window.load"的详细信息吗?
飞雪的回答是正确的。 如果要从 File2.aspx 获取主题,请在 Office.initialize 事件中添加与 file1 相同的 Office.js 引用和访问主题.aspx
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
相关文章:
- iframe响应为302时重新加载应用程序
- Chrome.storage.sync 在重新加载扩展程序时会被覆盖
- 安卓 - 加载应用程序时检查切换按钮的状态
- AngularJS - 预加载应用程序设置
- 加载应用程序.js在设备中准备好煎茶触摸科尔多瓦应用程序
- 加载处理程序上的事件参数
- 更改值后如何重新加载帮助程序
- 正在预加载引导程序图示符
- 如何在functions.php(wordpress)中加载引导程序脚本和样式
- 为什么我没有得到一个加载处理程序
- angularjs将加载应用程序延迟到指定条件
- Meteor不渲染css,并且在使用外部DDP Meteor实例时不断重新加载应用程序
- 使用AngularJS在加载应用程序时将用户导航到登录页面或其他页面
- 当初始化swiffy时,Safari会重新加载应用程序
- 如何在加载应用程序之前添加搜索功能
- JavaScript:在页面初始化时加载应用程序环境变量的最佳方式是什么
- 如何在使用选项卡集加载应用程序时使选项卡激活
- 如何在第一次加载应用程序时显示加载指示符
- Jquery Ajax在第一次加载应用程序时触发错误回调
- React Native:重新加载应用程序或强制重新发布程序