Embedding a Yammer feed into an interact homepage is a fairly common request, so let's look at that.
Looking at the developer documentation for Yammer, the embed code for the widget is available here. The offered code looks something like this.
If you were to copy this straight into an HTML widget the page would work and the widget would display when you first save the page, but subsequent loads of the page would appear blank. Taking a look at the console in the Chrome developer tools will yield an error similar to this.
This is caused because the script references an object called 'yam', but this is being called before the object has been created, therefore the script will fail and the widget will appear blank.
In order to get around this some additional code needs adding to test whether or not the browser knows what 'yam' is yet. If it does, then great! Carry on! If it doesn't, then wait a little while and try again.
This is shown below
In the modified script above, the relevant yammer code is abstracted into a function. Line 5 in the sample above checks to see if yam is a known variable. If it is, then we can carry on as normal. If not then the else branch is executed which tells the browser to call the function again in 500 ms.
Next time it runs (500ms later), there's a good chance the script has now loaded and the browser knows about window.yam so it can continue, but again, if not then simply repeat the process by waiting 500ms and trying again.
Updated over 1 year ago