How does StorageEvent work in Office Add-in? - javascript

I have 2 task panes in Word Add-in (using Office UI Fabric with React). I select item in first pane and then I write item's id to localStorage. In the second pane I press update button, so I can see details of the item.
I want to avoid pressing update button. So I tried adding window.addEventListener('storage', f) in the second pane, but it doesn't trigger.
Am I doing something wrong?
or
Does Add-in interpret itself as single window and that's why StorageEvent is not triggered?
And what alternatives do I have?
(Office.context.document.settings, SharedWorker, ...?)

I've consulted with the Office product team. Their experience is that the storage event does not fire reliably in add-ins, and that this is probably a problem with IE. They recommend that you poll local storage instead of relying on the event.

Related

Outlook365 Add-In Event on Change Attendee Action

I am working on to creating Outlook ADD-In for Outlook365 cloud account.
I want to capture event on attendees change i.e rather than manually clicking on Add-In icon for every change, if someones Add or remove some attendee from calendar invite, the event can be captured and some java script function can be called in my Add-In app.
In case your add-in is active and attendees are changed in appointment window, you can get events when attendees are changed. requirement set 1.7 for Outlook 2016 was made GA during IGNITE.
You need to handle RecipientsChanged events.
https://learn.microsoft.com/en-us/javascript/office/objectmodel/requirement-set-1.7/outlook-requirement-set-1.7?view=office-js
You can also refer to the following youtube video for an example
https://youtu.be/xbUcGlcnfxQ
In case you want without add-in being active, you need to use graph API web-hooks to get notified of the change.

I want to get an event for an HTML onContextMenu *after* the final selection, not at initial click

If I do
<a href ... oncontextmenu="myFunction(event)">
It gets called when the user right clicks on a link, before the context menu appears. But I want to get an event after a context menu item has been selected. Ideally, only when they have selected "Open link in ...", so having access to what they actually clicked is desirable.
Would prefer a non-JQuery answer, but if needed, JQuery is o.k.
Added: Explanation what I'm trying to do:
When the user directly clicks a link to another (commercial hotel finder) site, I bring up a little alert "If you book a room, please enter XXXX as the Gift Code"). Would also like to put up this alert if they right click and open the link in a new tab etc.,.,
Added#2: Thanks for the prompt and direct answers. See my "answer" below for what I ended up doing. I'll leave this question open in case there are other options.
This is not possible to do in Javascript, but you might be able to achieve what you are looking for by replacing the default context menu with a custom one.
You can't. The primary purpose of the contextmenu event is to allow a page to replace the browser's context menu with a menu of its own rendered as HTML. The contents of the browser's context menu are not specified by any HTML standard, and will vary from browser to browser. Most of the options in the context menu refer to actions outside the scope of the page (e.g, "copy", "view page source", "open link in new window", "save as", etc.), and there is no event fired on the page when they are selected unless the action being performed would normally fire an event. (For instance, selecting "Print" might fire onbeforeprint and onafterprint events.)
The WHATWG HTML5 specification specifies a menu element which can be used to add items to the browser's context menu, but it's currently only supported under Firefox. So that's probably not really an option either.
Just an idea, and I'm not sure exactly what you are trying to do, but I would try calling the function on a set delay, like this:
Right-Click Me, then wait for 3 seconds.
The only downside is that once the alert() is called, the context menu is hidden.
Hope this helps!
What I ended up doing is inserting an intermediate page on my site.
Instead of directly going to the external site, the route (I'm using node & Express) brings up a intermediate page with the explanatory text, a checkbox "Got it, don't show this page again", (in my case, the answer gets stored in localStorage, others might store on the server) and a big green OK button that takes you to the external site.
If the route includes the query "?directXXX=true", (read from localStorage) you skip over the intermediate page and are immediately redirected to the external page.
This way I get a much nicer explanatory page, with an image, etc... (dialogs, even if you use something like alertify, look klunky) and I get to "intercept" all calls to the external site.

Possible to read the selection of a subgrid in CRM2011?

I'm trying to be able to retreieve the selection of a SubGrid at the exact moment a user selects it. For example, add an EventListener OnClick that would make a JS function run in the background to do X thing when a subgrid element/row is selected without having to click Save or another button to run the function. Ive been searching online and alot of links appear for retrieving ALL records in a subgrid but none really show if one can add an EventListener. Another possibility would be to intercept when a subgrid is focused on and make that run a function. What do you guys think would be possible, always trying to keep the methods the supported way. :).
If your willing to be a little creative, you could try the following:
Add a custom ribbon button.
Add an enable rule to that ribbon button that calls a JavaScript library.
Add your logic into that JavaScript library.
When a record is selected in the sub grid, CRM will refresh the ribbon and call your enable rule.
I've only just thought of that so I don't know if it will work, but worth a try.
If that fails then I don't know any other supported way to have an OnClick event.
Edit, I've had a play and it does appear to be possible, see my blog post here: CRM 2013 Adding an On Change Event to a Grid View. Its for CRM 2013, but I believe can be adapted for CRM 2011 (see my note at the end).

Trying to add websites to localstorage in chrome extension options page

I want to be able to add websites to a chrome extension options page. So I have a text box with a "save" button and I want to be able to save multiple websites with the ability to edit or remove them later. Like this:
Enter URL: |_________| |_save_|
Edit Remove - www.google.com
Edit Remove - www.msn.com
Edit Remove - www.yahoo.com
Once you enter a website and click save, it will add it to the list of websites already there. I've been trying to scavenge the internet to try to figure out how to accomplish this, but I just don't know enough about it to complete it.
I'd recommend chrome.storage instead of localStorage: http://developer.chrome.com/extensions/storage.html
It's fantastic. You can even choose to store data online in your Google profile (100KB max). Otherwise offline (100MB max, I think).
API is super simple too:
chrome.storage.local.get('websites', function(items) {
console.log('websites:', items.websites);
});
Unlike localStorage, it's async, so you'll be using callbacks. But it's lightning fast, so the UI won't notice.
What I'd do is not keep a virtual record of your storage, but keep it in HTML and read from/write to that as necessary:
btnAdd adds a new LI to the list and then saves the list
btnEdit fills the textfield and removes the LI from the list (no save) (saving via btnAdd)
btnDelete removes the LI from the list and saves the list
save = get items from list as array and save to storage
init = load items from storage and fill list
http://jsfiddle.net/rudiedirkx/Zbpmx/
I'm assuming jQuery since it's popular. It's not necessary of course.
If you're having problems with this already, a Chrome extension will be insanely difficult.

Track bookmarking event

Any idea on how can I track users bookmarking event? I want to find out how many users are saving a specific page into their bookmarks, and every time this happens I want to call a callback function (i.e. AJAX) to store this data.
For what I know of JS this is not possible: I can initiate a bookmark creation, but this is not what I'm trying to do...
Even a jQuery plugin is ok. Thanks!
It's not possible. Bookmark creation is outside a web page's control.
I wonder, How CodeProject articles are showing the Bookmark Count then?
(See the 'About Article' panel # right side for the Bookmark count)
for example see this one

Categories

Resources