Unable to conceal iFrame ribbon in Sharepoint Online

Attempting to conceal an Office 365 ribbon in SharePoint, but encountering an issue...

TypeError: document.getElementById(...) is null

This is the snippet I'm experimenting with; I plan to implement display:none later...

document.getElementById('.content-frame').contentDocument.body.getElementById('#suiteBarDelta').style.visibility = 'hidden';

Any suggestions for a more effective approach?

Answer №1

Imagine you're inserting this script directly into the html file that includes the "parent" window code (which also contains the iframe). To ensure the iframe is properly defined when this code runs, position the script block after the iframe element, or utilize a window.onload or document.ready handler.

<iframe class='content-frame'></iframe>

...

<script>
document.getElementsByClassName("content-frame")[0].addEventListener("load", function () {
  // once the iframe's document has loaded, hide the ribbon bar
  var ribbonBar = this.contentDocument.getElementById("suiteBarDelta");
  if (ribbonBar) {
    ribbonBar.style.visibility = 'hidden';
  } else {
    console.log("Uh oh, ribbonBar still doesn't exist");
  }    
});
</script>

I can't be certain if Sharepoint utilizes complex processes to construct content within the iframe (such as asynchronous requests to fetch the ribbon bar) - if it does, this code will break and you'll see the "Uh oh" message in the console.

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

Chrome causing window.open to fail

I am currently working on developing a Cordova PhoneGap app and facing an issue with popping up a window for Facebook login after clicking a button. The popup works fine on iOS devices, but when I try debugging with Chrome, nothing happens even though th ...

Error message: Laravel unable to locate requested page

Attempting to make a post request using AngularJS in Laravel, I encountered the following error message: Oops! The page you are trying to access could not be found. JAVASCRIPT app.controller('main',['$scope','$http',&apos ...

Utilize the asynchronous power of Morgan to quickly display your

After investing a considerable amount of time into this task, I'm uncertain about its feasibility: Creating a reverse lookup of IP addresses and logging it through morgan Express.use(Morgan(async(tokens, req, res) => { async function ip_reverse ...

Guide on accessing values from an array of objects in JavaScript/Node.js

I am working with an array of objects that looks like this: const objArray = [{prop: "a", prop2 : "1"}, {prop: "b", prop2 : "2"}, {prop: "c"}, prop2 : "3"] My goal is to extract the property names of the objects in the array, rather than their values. D ...

Adjusting the width of a div element using a button

I am currently diving into the world of JavaScript, React, and Node.js. My current challenge involves attempting to adjust the width of a div element using a button. However, I keep encountering the same frustrating error message stating "Cannot read prope ...

jQuery.ajax encountering failure to read success function

Hey everyone, I need some assistance with web programming. I'm facing an issue with ajax while trying to read a JSON response. The catch is, I have to use Internet Explorer for this task, so switching browsers is not an option. I'm stuck because ...

Using Conditional Rendering and ReactCSSTransitionGroup for Dynamic Animations

I have developed a small application that displays different components based on a Redux state. I am trying to add a "fade" animation when one of the components renders, but unfortunately, it is not working as expected. Here is my current setup: content.j ...

What is required to create a basic application that can function offline while featuring an HTML/CSS user interface?

Newbie inquiry: I am interested in creating a small application that can run offline on a desktop computer. The amount of data to be saved is minimal, so I have the option to use a file or some type of database. However, my main question is: What languag ...

Error message indicating unauthorized access while trying to implement Backbone with Slim framework and Tuupola basic authentication

I've been working on connecting my Backbone app with my server API (using Slim) and have implemented Tuppola / Basic Auth Middleware to handle authentication. The setup is fairly simple, as I'm just trying to make it work. When I access the serv ...

Transmit the identification to angularjs for the genuine content to be displayed

I have a hidden field where I store an Id, which can also be 2, 3, 4, or 59. I need to send this Id from the hidden field to my opgaver.js file so it can download the content. However, I am facing difficulty in figuring out how to pass the Id to the opgav ...

The Bootstrap Navbar is causing the navigation bar to span across two lines

I'm having an issue with my navbar taking up two lines on desktop resolution, but fitting perfectly on mobile. I've spent hours going through the code with no success. Any help would be greatly appreciated. The HTML code is provided below. <! ...

Combining two objects by id and grouping identical key-value pairs together

var routePlan = [ { "id" : 1, "farmerName" : "Farmer1", "farmerId" : 1 }, { "id" : 2, "farmerName" : "Farmer2", "farmerId" : 2 }, { "id" : 1, "farmerName" : "Farm ...

Tips on pairing elements from a ngFor processed list with another list using ngIf

If we have a list such as the one shown below: elements = [ { id: 1, name: "one" }, { id: 3, name: "three" }, { id: 5, name: "five" }, { id: 6, name: "six" }, ]; lists = [ { id: 5, name: "five" }, { id: 9, ...

Sub-menu disappears upon resizing the screen

Currently, I am working on creating a unique responsive navigation system that transforms into a 100% width pulldown menu for mobile devices. To achieve this functionality, I have implemented some JavaScript code that hides any open sub-menu items when the ...

Tips for sharing data between React components without causing re-renders or relying on JSX, such as through a function within functional components

As a beginner in react, I have been struggling to find answers to this issue. I am trying to figure out how to pass data from one functional component to another in react without actually rendering the child component. Does anyone know a solution for this ...

What type of technology is typically utilized in creating functional platforms such as goDaddy, wix, and other web design websites?

I am currently working on a web development project that aims to allow users to edit webpages without needing any coding knowledge. Users with authorization will be able to modify not only the text but also various HTML tags on the page, similar to platfor ...

The drop-down menu keeps flickering instead of remaining open when clicked

I am facing an issue with a dropdown menu in my webpage. The menu is initially hidden, but should become visible when the list element containing it is clicked. I have written JavaScript code to add a class that changes the visibility property to visible u ...

Exploring the boundaries of React's useContext functionality

In my applications, I specialize in creating custom hooks for accessing state stores. For example, I typically define the hook like this: const store = new Store(); const StoreContext = createContext(store); StoreContext.displayName = "StoreContext"; fun ...

What is the process for converting a URL or HTML document to a PDF using the html2pdf JavaScript library?

I am working on creating a button that utilizes the html2pdf library to convert an HTML page into a PDF. Instead of selecting an element with query selector or getElementById, I would like to pass a URL because the page I want to convert is not the same as ...

How is it possible for this for loop to function properly without the need to pass the incrementing variable

I managed to compile my code and it's working fine, but there's something interesting - the variable that should reference the incrementing value is not included as an argument in the for loop. var _loop2 = function _loop2() { var p = docume ...