如何正确检查主机:Office,Office Online和Web浏览器 [英] How to correctly check the host: Office, Office online and web browser

查看:139
本文介绍了如何正确检查主机:Office,Office Online和Web浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检测用户是否从Office和Office Online的外部浏览器中访问了我的加载项的URL. (我在这里看到过有关检测它是Excel还是在线Excel,但不是都不的问题.)

I need to detect whether a user has hit the URL of my add-in from a browser, outside of Office and Office online. (I've seen questions here about detecting whether it is Excel, or Excel online, but not neither of them.)

我看过实用程序功能OfficeHelpers.Utilities.hostOfficeHelpers.Utilities.isAddin,但是

I've looked at the utility functions OfficeHelpers.Utilities.host and OfficeHelpers.Utilities.isAddin but the code notes say these will only work after Office.initialize is called. If the URL has been navigated to from outside of an Office client then this won't be the case (?).

因此,我认为我需要与收到警告时进行的检查相同的检查: 在Google Chrome浏览器中进行警告 ...以确保不会运行Office.initialize,不是尚未运行 .

So I think I need to perform the same check as whatever is being done when you get the warning: Warning in Google Chrome ...to make sure that the Office.initialize will not be run, not that it hasn't run yet.

一个简单的用法是将用户定向到一个页面,该页面显示说明他们在不将其作为加载项加载的情况下无法访问此页面,以及有关如何加载加载项的说明等.

A simple use of this, would be to direct users to a page that displays explains they cannot access this without loading it as an add-in, and instructions on how to load the add-in etc.

我试图获得的实际结果是将两种情况都处理为:

The actual result I am trying to get is to handle both cases as:

在Office客户端中:"GetData"将返回一些值并将其写入文档. 如果从浏览器访问:"GetData"将返回一些值并重定向到视图以显示这些值.

From within an Office client: "GetData" will return some values and write them to a document. If accessed from a browser: "GetData" will return some values and redirect to a View to display these.

推荐答案

目前还没有很好的解决方案,尽管我同意这里有机会公开"Office.ready"以提供明确的标志Office.js以一种或另一种方式加载-并且主机和平台现在已经稳定确定(包括确定为稳定的"web"和null).

There is no great solution for this at the moment, though I agree that there is an opportunity here to expose an "Office.ready" to provide a definitive sign that Office.js loaded one way or another -- and that the host and platform are now stably determined (including determined to be stably "web" and null).

对于脚本实验室,我们使用的方法是等待Office.js三秒钟,然后给出并向用户显示一组令人反感的按钮,要求他们选择主机.那时我们可能可以安全地假设为网络",但是在我们的情况下,无论如何我们都希望提供消除歧义的体验,因此用户可以选择运行网络摘要还是查看需要特定主机选择的特定于主机的摘要

For Script Lab, we use the approach of waiting on Office.js for three seconds, and then giving up and displaying a disambuguation set of buttons to the user, asking them to choose the host. We could probably safely assume "web" at that point, but in our case we want to provide a disambiguation experience in any case, so users can choose whether to run web snippets or view host-specific ones where they would need a host choice anyway.

如果您想知道它是如何完成的,请参见

If you're curious to see how it is done, see the "initialize" function in https://github.com/OfficeDev/script-lab/blob/eeb4ba89a7a570cf1bb035fdd740ec7dcfb92822/src/client/app/helpers/environment.ts

这篇关于如何正确检查主机:Office,Office Online和Web浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆