Comments (14)
@SoftTimur , @KingHenne , @ershwetabansal , @fergiemcdowall : I'm happy to say that we're close to having an API that will fulfill this need. In fact, you can dogfood it already (just for your own testing, don't use it in production yet!) -- instructions lower down.
To give a bit of background: The issue with today's Office.initialize
is
- It does not fire on the web -- which is what this thread was about.
- The place where you call it makes a difference. Call it too late (e.g., 3 seconds later in a
setTimeout
, to use a contrived examples), and it won't fire. - You can only have a single
Office.initialize
declared (you can't have multiple ones, because you're directly setting the object).
The good news is that this is going to change very soon! We are about to release an API to replace (or rather, append, but with the intention of having one supercede the other) Office.initialize
with something that addresses both issues. An "Office.onReady" API, that can be used as follows:
Office.onReady(function() {
console.log("Office is now ready 1!");
});
Office.onReady(function() {
console.log("Office is now ready 2!");
});
// And both should fire, after the host is ready
or as a Promise:
Office.onReady()
.then(function() {
console.log("Office is now ready 1!");
});
Office.onReady()
.then(function() {
console.log("Office is now ready 2!");
});
or even with TypeScript's async/await:
(async () => {
await Office.onReady();
console.log("Office is now ready!");
})();
And with Office.onReady, it shouldn't matter where you call it. If you call it before the host is ready, we will wait to fire it until the host is ready. Or if you call it some time later, we'll just immediately fire -- just like jQuery's $(document).ready
.
If you'd like to try it, could you please reference the build from https://unpkg.com/@microsoft/[email protected]/dist/office.js, and see whether this API works for you. (Unpkg is a virtual CDN service, not affiliated with Microsoft -- but it does provide an easy way to test things, and is often used elsewhere in the web community). If it works, the good news is that the API should be on the CDN soon (in a matter of weeks). If it doesn't, then we have to dig deeper.
Would love to get your usage and input before the API goes live, in the coming weeks...
Thanks!
from office-js.
@SoftTimur, in case it helps. I have recently added a functionality in one excel addin to be able to test it in the browser. I am initialising it in the browser by checking typeof Office.context === 'undefined'
. Because this API will not be present in browser in case you are using Office Javascript API.
from office-js.
FYI, the onReady
feature has not shipped to the production CDN.
Note there is still one issue (currently being investigated), where it look like on some hosts/platforms (specifically, Outlook Online, but maybe others), there currently still is a requirement to have an "Office.initialize" in order to get the add-in to load. Having it be empty is totally fine: Office.initialize = function() { }
. So for now, just be aware that you may still need to include Office.initialize
to appease the framework, but you can use onReady
for the actual work.
from office-js.
OK, thanks for pinging this. Let me re-bring it up to the team in terms of trying to get this addressed on the sooner side...
from office-js.
Just for reference, here is the StackOverflow question that started this:
https://stackoverflow.com/questions/44989152/check-if-office-js-is-loaded-outside-of-office-client/44989990?noredirect=1#comment76977223_44989990
from office-js.
We also need this feature. We would like to redirect to a different URL (or show a help view without redirecting) when the add-in has been loaded outside of an office client, which could for example happen when the user command-clicks on a link within the add-in.
from office-js.
I met the same issue, and this helped me.
So, when will it be fixed?
from office-js.
@hongbo-miao , FYI that an internal partner brought this up today as well.
from office-js.
Had a conversation with Michael Zlatkovsky, we are starting the new API design now.
from office-js.
@ershwetabansal yes, that works quite well
from office-js.
Hello, @Zlatkovsky,
I noticed that the API is already in the production CDN and I tried it.
While it seems to be working fine in some hosts, in Office Online is resolving the promise even before the Office.Initialize event is triggered. This means that we still wouldn't have access to the context API when the onReady promise is resolved the first time.
Cheers!
from office-js.
@raulgg, that definitely seems like a bug. Let me see if someone can take a look at it.
from office-js.
Opening #200 in place of this one, to track the Office Online issue
from office-js.
I hope this isn;t too far off topic, but I have a question:
I ham finalizing the JS and CSS loading for an Office add-in, and need to write a fallback for the Office CDN. I have one for jQuery that works, but I don't know what to check for if the AppsForOffice files do not load. What object do I need to test for? I've searches around and did not find any example code for this CDN. I've tried testing for either Office or OSF.
jQuery Example (does work)
<!-- jQuery CDN and fallback -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous">
</script>
<script>window.jQuery || document.write('<script src="../../Scripts/jquery-3.3.1.min.js">\x3C/script>')</script>
AppsForOffice Example (does not work)
<!-- Office CDN and fallback -->
<link rel="preconnect" href="https://appsforoffice.microsoft.com">
<script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js"></script>
<link rel="stylesheet" href="https://appsforoffice.microsoft.com/fabric/2.6.1/fabric.min.css">
<link rel="stylesheet" href="https://appsforoffice.microsoft.com/fabric/2.6.1/fabric.components.min.css">
<script>
window.Office ||
document.write('<script src="../../Scripts/Office/1/office.js">\x3C/script>')
document.write('<link rel = "stylesheet" href = "../../Content/fabric.min.css" />')
document.write('<link rel="stylesheet" href="../../Content/fabric.components.min.css" />')
</script>
As mentioned, what object do I need to test for?
from office-js.
Related Issues (20)
- Outlook Add-in Centralized Deployment - Not working HOT 8
- [Translation] Outlook report button translation HOT 1
- Word hangs when attempting to undo a change that insert four or more comments HOT 4
- How to use workbox in Excel Addin HOT 3
- Access custom spam reporting features in other menus HOT 1
- In a custom Spam reporting add-in, microsoft defender is not triggered HOT 1
- Custom function "error installing functions" via Admin Managed. Working on Local and Sideload HOT 21
- Get username of current user HOT 3
- Spam addin event.options is an array in classic outlook and is an object/structure in browsers/new look outlook. HOT 1
- Outlook 365 add-in not loading on MAC/OS new Outlook app. HOT 8
- Powerpoint Add-in is not updating automatically without any notification HOT 5
- Custom function handling of Entity Value is broken again HOT 4
- Office.context.roamingSettings.get() size limit HOT 2
- Word close API not working HOT 3
- Excel close is not working HOT 10
- Powperpoint close API HOT 4
- Manifest file sideloads on Excel web but does not sideload on Mac or Windows os HOT 2
- Opening dialog in iframe for an Excel custom function handler fails on alternate invocations HOT 6
- Outlook Add-in - Call to mailbox.getUserIdentityTokenAsync returning undefined token for only some Outlook accounts
- Assistance Needed with Outlook Add-In installing Manifest for older version of Outlook HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from office-js.