Forum Discussion
calendar web part on modern pages
Hi! I have been using this code to embed my calendars. Last week it magically stopped working and now the left and top nav that should be cut off with the margins are showing.
Any idea how to fix this and/or why it changed? No code changed on my pages. One minute the iframe margins worked, and the next time I opened the page, the iframe margins weren't working anymore.
Below is an answer I received from Microsoft on a modification to the javascript in order to display the calendar in a better manner. I didn't want to modify the code for something that is fairly trivial for me so I can't say if this works or not. I also asked them what changed in the last week or so and they didn't have a response for that.
Microsoft Answer:
If only want to display the calendar in the modern experience page like this,
You can try these below steps,
- On the calendar page(which you want to display on the modern page), edit the page, add one content edit web part and insert below JavaScript code in the content edit web part,
<script>
function HideElementInFrame(Id)
{
ele = window.document.getElementById(Id);
if(ele)
{
ele.style.display="none";
}
}
var url = new URL(window.document.location.href);
var IsInIframe = url.searchParams.get("IsInIframe");
if(IsInIframe==1)
{
HideElementInFrame('s4-ribbonrow');
HideElementInFrame('s4-titlerow');
HideElementInFrame('zz12_V4QuickLaunchMenu');
HideElementInFrame('zz11_RootAspMenu');
HideElementInFrame('DeltaPlaceHolderSearchArea');
HideElementInFrame('suiteBarTop');
}
</script>
2. On the modern page, embed the calendar page with below code,
<iframe src="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fghtulsa.sharepoint.com%2Foperations%2Fnew-accounts%2FLists%2FXdocs%2Fcalendar.aspx&data=02%7C01%7Cabrcheng%40microsoft.com%7C3bd81b51a2b54c5a12ef08d67a380940%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636830778434955701&sdata=hnPRS%2FgBt%2BeN%2F0Qk730lZ05pjCG0Hk%2FxZbpSzPum5JA%3D&reserved=0?IsInIframe=1" scrolling="no" width="100%" height="1000px">
</iframe>
- MahmudaJan 03, 2020Copper Contributor
Hi Josh, JHMSTechComm
I am also attempting to get the full view of the calendar on to my modern SharePoint site. Once I click Edit Page, I do not see the Edit Source button to edit/enter a JavaScript code under HTML Source. See image below. Please let me know if I am missing a step?
Thanks,
Mahmuda
- DsienkowskiJan 03, 2020Copper Contributor
You need to add a Content Edit Web Part. See my comment above on how to do that. I've attached the web part if you need to import it like I did.
- MahmudaJan 03, 2020Copper Contributor
Hi Dsienkowski
Thank you for your reply.
I followed those steps, however, on my modern page I am still getting all the left-hand side options and top ribbon. How can I get just the calendar? See below image.
- Robin NilssonJan 18, 2019Bronze Contributor
This looks promising - it's like what I would do for on-premise SharePoint. However, there isn't a Content Editor Webpart available unless you turn on the publishing features for your site collection. Which might be a problem, or not - I've seen other posts about publishing features and unintended consequences but I don't remember what they actually said.
- NHarzicJan 21, 2019Iron Contributor
Thank you for this. I have implemented this solution and it does the trick. However, instead of putting the JavaScript in a Content Editor webpart on the source calendar page though, I used a script editor.
I will say that it does seem a shame to use embedded JavaScript when a fully-functional modern calendar webpart with options for re-sizing and styling would be so much better and more reliable. Hopefully this is something that the Microsoft development team is considering in the near future as it would really solve a lot of problems.
Thanks, Natalie