如何基于正则表达式在O365邮件应用程序中加载不同的页面

时间:2016-04-24 15:16:15

标签: javascript office365 office365-apps office-js

我正在创建一个O365应用程序,我有2个.aspx文件,当用户点击O365邮件应用程序时,我希望根据邮件主题加载每个页面。

场景1:邮件主题包含“#” 结果:加载page1

场景2:邮件主题不包含“#” 结果:加载page2

我尝试过编写逻辑的中间.js文件, 但当我做window.location =“path_to_aspx_file”时, 只加载了html,但js文件没有运行。

我目前的实施:

我有LandingLogic.js

import 'dart:isolate';
import 'dart:async';

SendPort replyTo;
bool OK = false;
const timeSlice = 100;

main(List<String> args, SendPort reply) async{
  var response = new ReceivePort();
  reply.send(response.sendPort);
  replyTo = reply;
  response.listen((msg) => messageReceived(msg));
  replyTo.send("Hello from worker. Click to start and stop me");
}

messageReceived(String message){
  switch(message){
    case 'stop':
      replyTo.send('idle');
      OK = false;
      break;

    case 'go':
      replyTo.send('working');
      go();
      break;
  }
}

go()async {
  OK = true;
  int i = 0;

  batchJob(){
    int startTime = new DateTime.now().millisecondsSinceEpoch;
    int elapsed = 0;

    while(elapsed < timeSlice){

      i ++; // the central routine

      elapsed = new DateTime.now().millisecondsSinceEpoch - startTime;
    }
 }

  while(OK){
    batchJob();
    replyTo.send(i.toString());
    await new Future.delayed(const Duration(milliseconds: 0), () {});
  }
}
经过一番摸索之后。 我现在能够导航到每个文件,但我不知道如何从File1.aspx和File2.aspx访问邮件主题。

2 个答案:

答案 0 :(得分:0)

在使用Office JavaScript API获取主题之前,您是否初始化了Office上下文?要轻松地重定向HTML页面,我们可以包含以下JavaScript:

Home.js:

CREATE EXTERNAL TABLE test
PARTITIONED BY(brand STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
STORED AS
INPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
TBLPROPERTIES
('avro.schema.url'='/user/test/schema');
ALTER TABLE db.test ADD PARTITION (brand="child1") LOCATION '/user/test/output/brand-child1';
ALTER TABLE db.testADD PARTITION (brand="child2") LOCATION '/user/test/output/brand-child2';
ALTER TABLE db.testADD PARTITION (brand="child3") LOCATION '/user/test/output/brand-child3';
ALTER TABLE db.testADD PARTITION (brand="child4") LOCATION '/user/test/output/brand-child4';

重定向的HTML页面:

/// <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";

    }

}

})();
  
    

我尝试过编写逻辑的中间.js文件,但是当我执行window.load =“path_to_aspx_file”时,只加载了html但js文件没有运行。

  

你介意使用“window.load”分享你的细节吗?

答案 1 :(得分:0)

费雪的回答是正确的。如果你想从file2.aspx获取主题,请在Office.initialize事件中添加office.js引用并访问与file1.aspx相同的主题

<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>