Sharepoint iframe resize issue causing postMessage to not work properly

I've been struggling to resize an iframe within a Sharepoint environment using Cross Domain. Despite trying numerous solutions found online, the only one that seems to work is Baker Humadi's postMessage solution mentioned towards the end:

To implement this, I added a Script Editor to the Sharepoint page with the following code (Replace the iframe URL with your own child page URL):

<script>
// Creating a compatible event handler for IE and other browsers
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";

// Listening to messages from child window
eventer(messageEvent, function(e) {
    document.getElementById('frame').height = e.data + 'px';
}, false);
</script>

<iframe id="frame" src="childpage" scrolling="no"></iframe>

In the child page, include the following code snippet (RestSection is assumed to be filled by other means):

<script type="text/javascript">
window.onload = function() {
    var actual_height = document.getElementById('RestSection').scrollHeight;
    parent.postMessage(actual_height, "childpage"); 
    //* This allows posting to any parent iframe regardless of domain
}
</script>

<div id="RestSection">
    //List of things
</div>

While editing the code snippet in Sharepoint, the resizing works correctly. However, after checking in, the resizing stops working and I notice the height being set strangely - could it be related to a postMessage object?

<iframe id="frame" src="childpage" scrolling="no" height="{"command":"RequestSuccess","requestIndex":1,"result":null}px"></iframe>

I am puzzled by why it works during editing in Sharepoint but fails after checking in. Has anyone experienced this issue before or can provide some insights?

Answer №1

Seeking assistance is always a good idea. If you're having trouble with a script that functions in edit mode but not in view mode, you may find helpful resources on the SharePoint subsite . It's a common issue that many users encounter.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

extract data from a JavaScript object

Currently facing an issue extracting a String name from the JSON object's name. It is necessary to parse this type of JSON response obtained from the server. var response = { hopaopGmailsjIpW: { GmailsjIpW_totalEmails_count: 133, GmailsjIpW ...

Troubleshooting: Angular ng-if not correctly detecting empty strings

When looking at my code, I have the following snippet to showcase data from angular scope variables. The initial two lines are functioning correctly and displaying data from the scope variables; however, there seems to be an issue with the line using ng- ...

What is a method to mimic the presence of JavaScript using PHP Curl?

Is it possible to parse HTML code from a webpage using PHP Curl even if there is an error message stating that JavaScript is required to access the site? Can PHP Curl be used to enable JavaScript on a webpage? ...

javascript display hide choose among

I am attempting to display another set of options when the user selects a specific item. For example, if the user selects "Products," then a new selection box should appear with different product types. See my code below: <html> <head> <m ...

Preventing Copy and Paste and Right-Click Actions With JavaScript

Similar Question: How can I prevent right-click on my webpage? Looking to prevent right-clicking and key combinations like Ctrl+V & Ctrl+C on a webpage using JavaScript. I have a form where customers need to input their details, and I want to avoid ...

Analyzing length of strings by dividing content within div tags using their unique ids

Here's my issue: I'm using AJAX to fetch a price, but the source from where it is fetched doesn't add a zero at the end of the price if it ends in zero. For example, if the price is 0.40 cents, it comes back as 0.4. Now, my objective is to t ...

Utilizing JQuery to make Google listings easily findable

Implementing Google Places for a location text box has been successful. However, I am now looking to create a class-based implementation so that I can use it with multiple places effortlessly. Is it possible to achieve this using JQuery? <script type ...

Dealing with numerous promises simultaneously using AngularJS Factory

I have created a code that makes multiple $http calls recursively and saves all the promises it returns in an array. Then, I resolve all of them and save the responses in another array. Now, my question is: How can I efficiently return this final array to ...

Tips on customizing the color of checkboxes in a ReactJS material table

I'm working on a project that involves using the Material table, and I need to change the color of the checkbox when it's selected. Can anyone help me with this? https://i.stack.imgur.com/JqVOU.png function BasicSelection() { return ( <M ...

Retrieving the chosen item from an unordered list using jQuery

Hello, I am currently populating a list using the ul-li HTML tags dynamically. My goal is to retrieve the value of the selected li within the corresponding ul. Despite trying various jQuery methods, I keep getting 'undefined'. Here is how I popul ...

What is the best way to trigger a re-render in a child component in React using forceUpdate

Is there a way to force reload a child component in React, similar to using this.forceUpdate() for a parent component? For example, consider the following scenario: buttonClick = () => { // This updates the parent (this) component this.forceUpda ...

Trouble arises with Pagination feature of Mui Data Table

Currently, I am working on a project that involves retrieving data from the CoinMarketCap API and presenting it in an MUI Data Table (specifically a StickyHeader Data Table). However, I have been encountering difficulties with changing the color of the tex ...

Guide on displaying link parameter information on a separate webpage using only JavaScript

While doing some research, I came across an issue. I have a page called specifications.html with three links: details.html?id=1, details.html?id=2, and details.html?id=3. My goal is to display the details of each link when someone clicks on it. For examp ...

Problem with pairing table rows and cells, slight misalignment of 1 pixel

In my attempt to align an icon and text side by side, with the icon on the left and the text on the right, I encountered an issue where the element's box seems to be consistently 1 pixel off. This misalignment is causing the text to not line up proper ...

Click here to navigate to the same or a different page using an anchor

I'm currently implementing this code: $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostna ...

Clear the cache following the service call

I am currently working on a service that has two methods. Utilizing the built-in cache support for $resource, I am trying to implement a way to refresh the cache when a service call is made from the controller. I attempted to use $cacheResource without suc ...

Is the treatment of __proto__ different in the fetch API compared to manual assignment?

When using fetch to retrieve a payload containing a __proto__, it seems that the Object prototype is not affected in the same way as when directly assigning to an object. This behavior is beneficial as it ensures that the Object prototype remains unaffect ...

An effective method for selecting data within table rows using jQuery

I have a table with multiple rows that follow the same format: <tr role="row" class="even"> <td><input type="checkbox" id="valj4"></td> <td>Generell grupp</td> <td><a href="/Home/DeviceDetails?uuid=2b9fe5 ...

There are currently no articles found that match the search query

Recently, I started working with Django, but I am facing an issue with slug. Whenever I send a request to the Slug, I encounter an error. The error message I receive is: Articles matching query does not exist. Furthermore, I am facing another error while ...

Error encountered when attempting to integrate FontAwesome into the body of a Next.js Link

I'm currently using the react-fontawesome library in my project built with Next.js. However, I've encountered an issue when trying to include an icon inside the Link component. The error message is confusing and I can't seem to figure out wh ...