Incorporate some flair into the Twitter iframe with a Style tag

I have been attempting to add a style tag into the head of an embedded Twitter timeline in order to customize some of the styling. I wrote the CSS and added it within a style tag. My initial idea was to inject this into the iframe using jQuery, but unfortunately, it doesn't seem to be working.

window.setTimeout(function () {
  $('#twitter-widget-0')
      .contents()
      .find('head')
      .append(
          '<style>div.css-1dbjc4n > section[aria-label="Timeline"] > div{display: grid !important;grid-template-columns: 1fr 1fr 1fr;}.css-1dbjc4n.r-140t1nj.r-qklmqi.r-1cbz2o1 {display: none;}.css-1dbjc4n.r-14lw9ot.r-1ets6dv.r-1q9bdsx.r-rs99b7.r-1udh08x {border: none;}.css-1dbjc4n.r-140t1nj.r-qklmqi {border: solid 1px #e3e6f0;border-radius: 10px;margin: 10px;box-shadow: 0 0.15rem 1.75rem 0 rgb(58 59 69 / 25%) !important;}</style>'
      )
  $('#twitter-widget-0').css('height', '600px')
  console.log("twitter styling bits")
}, 15000);  

While it successfully identifies the iframe and its id (as the height changes to 600px), the style tag isn't being added to the head?


Edit

The iframe code is as follows (I haven't included the entire content due to its length as it's the Twitter timeline) and my aim is to simply insert elements into the head tag.

<iframe id="twitter-widget-0" scrolling="no" frameborder="0"
    allowtransparency="true" allowfullscreen="true" class="" style="position:
    static; visibility: visible; width: 1092px; height: 600px; display: block;
    flex-grow: 1;" title="Twitter Timeline" src="...">

<html lang="en" dir="ltr" style="overflow-y: scroll; overscroll-behavior-y:none;">
    <head>
      ...
    </head>
</iframe>

Answer №1


The content within an iframe cannot be manipulated unless you have access to the source of the iframe.

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

Having trouble getting a styled button to align properly with the text next to it

Usually I wouldn't reach out for help on a minor issue, but I've exhausted all my options. I've spent at least an hour attempting to solve this problem with vertical-align, padding adjustments, and more. It should be a simple fix. http://js ...

Retrieve the element's value in relation to a different parent element

[JavaScript] How can I access the value of a textbox related to a button through jQuery? The event is triggered when the .button-action is clicked <td class="dmsInput"> <input type="text" maxlength="4" size="4" class="d"> </td> <td& ...

How can the jQuery click() method be utilized?

Currently working on a web scraping project, I have managed to gather some valuable data. However, I am now faced with the challenge of looping through multiple pages. Update: Using nodeJS for this project Knowing that there are 10 pages in total, I atte ...

Issue with Google Maps Marker Being Strangely Stretched

I have come across an odd issue with Google Maps (as shown in the attached image). Does anyone have any insight into why this might be happening? Has anyone else encountered this before? Check out the code snippet below: <script> <!-- var ...

Learn how to utilize JQuery for downloading a file or incorporate Ajax to showcase an error page

I am currently developing a single-page application utilizing ASP.Net Core MVC and JQuery. Due to the fact that full-page refreshes would reset some lengthy processes, I have opted to implement AJAX for all navigation tasks. One of the functionalities I a ...

Fade out with CSS after fading in

After setting an animation property on an HTML element to display it, I want the same animation in reverse when a button is clicked to hide it. How can I achieve this effect? "Working Animation": .modal { animation: myAnim 1s ease 0s 1 normal fo ...

Discover the position of a chosen element using jQuery

Greetings! I am looking to retrieve the index of the column of a selected item in a table in order to create a color indicator in the header of the table. As the mouse moves, I want the header of the table containing the element to change color. Below is ...

The issue of the hamburger icon appearing as "X" seems to only affect certain mobile phones, while it displays correctly on desktops and most other mobile devices. The problem appears to be specifically

On certain mobile phones, the hamburger icon displays as an "X" instead of three horizontal lines. This issue specifically affects all XIAOMI mobile phones on various browsers, while most other devices and desktops show the correct hamburger icon. The < ...

When a promise is executed, it runs the code synchronously regardless of the promise

Essentially, I have a web application that fetches data from Firebase. Due to the time it takes to retrieve this data, I've implemented promises in JavaScript to ensure my code executes at the appropriate times. Within the function getDataFirebase, in ...

Numerous asynchronous requests running simultaneously

After successfully querying a database using js/ajax for a single drop-down, I am now looking to enhance my solution by adding multiple identical drop-downs. The goal is to retrieve the same information when an option is selected without allowing duplicate ...

The presence of element a within the element ul is not permitted in this particular scenario. Additional errors from this section will not be displayed

Having trouble with this code snippet: <nav role="navigation"> <div id="menuToggle"> <input type="checkbox"/> <span></span> <span></span> <span></span> ...

Steps for creating a JavaScript session expiry notification:

Ensuring user session continuity is essential, especially before it expires. In a recent quest on Stack Overflow, I inquired about detecting a dead session and alerting the user. A solution involving AJAX/JSON was proposed, but it inadvertently kept the s ...

Conceal the page's content as it moves beneath a stationary div

My issue involves a fixed div position with a margin from the top of the page. When I scroll my page, the content of my relatively positioned div (containing page content) is visible under the fixed div due to the margin from the top of the page. Despite s ...

Executing a function on each page within the head tag in Nuxt.js

I successfully made my function accessible by using the plugin attribute in the nuxt.config.js file, allowing me to call the function under mounted on every page. I am looking for a more efficient way to run this function within the head tag and have it b ...

Increasing the size of text in CSS with the use of ":hover" and then causing it to return to its original smaller size

Allow me to explain my goal here. I have text displayed on my website that I would like to enlarge when the user hovers over it and then shrink back down when they move their cursor away. The issue I'm facing is that after enlarging the text using t ...

Increase the quantity with animation

I am attempting to increment a number within an element on the page. However, I require the number to have a comma included while the increment should only increase by 1 digit every second. The code is currently functional, but I am facing a dilemma regar ...

What is the best term to use for the collection objects that are circulated among jQuery functions?

Is there a commonly accepted name for the objects manipulated by jQuery? jQuery primarily uses chain-able function calls that handle and return collection objects containing different HTML or DOM nodes, which may or may not be interconnected. They are o ...

The data from the Flickr API is consistently unchanging

I created a simple weather app that retrieves weather data using a "POST" request and displays it successfully. Users have the ability to search for weather by city, and I wanted to enhance the app by loading an image of that city through a separate jQuer ...

Create a feature that allows users to view photos similar to the way it

I want to incorporate a Twitter feed on my website that displays images posted. Instead of having the images redirecting users to Twitter when clicked, I would like them to reveal themselves underneath when a link labeled "View Photo" is clicked, and then ...

Enhancing 2D video viewing with Threejs interactivity

I want to create an interactive 2D video using three.js and maintain the aspect ratio of the video when resizing the browser window. Here is the code I am currently using: var camera, scene, renderer; var texture_placeholder, distance = 500; init() ...