Steps to modify the background-color of an iFrame using CSS

I am attempting to extract HTML code from an iframe and apply a background-color to the class: class="body"

The structure of my HTML source is as follows:

<iframe id="sc_ext_XT29EK" class="sc_ext" width="100%" height="1300px" frameborder="0" src="some-url" scrolling="no">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<body class="body">

    ....

</html>

I have made an attempt with jQuery code, but it did not yield the desired result.

<script type='text/javascript'> 
    $('iframe').load(function() {
        $("iframe").contents().find(".body").css('background-color', 'red'); 
    });  
</script>

Initially, I tried to verify if the color change was effective. If successful, I aim to set the background-color to none.

Do you think this is achievable?

Thank you.

Answer №1

Unfortunately, it's not feasible to access the DOM of a webpage from a different origin. The security protocols in place prevent such actions.

However, if you can get skycheck on board, there is another solution. By utilizing window.postMessage, you can send a message to the framed page and have it respond accordingly by setting the desired class.

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

Leveraging async.js to perform in-depth population in sails.js

Facing a major challenge with my function in sails.js (v12). I am attempting to retrieve all userDetail using async (v2.3) for deep populating my user info: UserController.js: userDetail: function (req, res) { var currentUserID = authToken.getUserID ...

Is there a way to set the content to be hidden by default in Jquery?

Can anyone advise on how to modify the provided code snippet, sourced from (http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_hide_show), so that the element remains hidden by default? <!DOCTYPE html> <html> <head> <scrip ...

Trouble arises with CSS flexbox functionality when connecting to Bootstrap 4 CDN

I'm currently utilizing CSS flexbox to design the header of my webpage by using display:flex; However, I've noticed that when I include the Bootstrap 4 CDN link in my HTML, the flexbox no longer functions as intended and the different divs within ...

Javascript problem involving multiple scopes in closures

What is the most effective solution for addressing this issue related to closure in JavaScript? Here is a simple problem I am facing: I have 10 spans with onclick events (I want an alert showing the number of the span clicked on each click): var spans = ...

sequenced pauses within a sequence of interconnected methods in a class

scenario: There are two javascript classes stored in separate files, each utilizing a different external service and being called within an express.js router. Refer to the "problematic code" section below: route routes.post('/aws', upload.sing ...

Let's unravel this JavaScript enigma: the code snippet window.confirm = divConfirm(strMessage) awaits

Imagine a scenario where you have an old website with a lot of existing JS code. If a user wants to update all the alert messages to modern, stylish Div-based alerts commonly used in jQuery, YUI, Prototype, etc., there are primarily three types of JS dialo ...

iOS is not recognizing the <a> tag but is instead honoring the :hover property

Within my list, I have a div element wrapped in an anchor tag. Here is an example of the code: <li> <a href="http://google.com/"> <div id="tease-info"> <div class="inset-img-border fade"></div> <img src=" ...

Fully compatible with Internet Explorer 6, with a height of

Is there a way to create a div that is always 100% the height of the browser, even if it's empty, and works in IE6? Any suggestions or hacks using CSS? ...

Is there a way to access the userID in the React.js front-end?

As I work on completing my Full Stack Web app with JWT token authentication based on roles, I find myself facing challenges with the front-end development. Specifically, I am unsure of the best practice for retrieving the UserID in the front-end to facil ...

Text field imposter - How to move icon to the right when focused

http://jsfiddle.net/g54p4/ If you need to view the HTML and CSS, it's available on jsfiddle. <div class="box-input"> <input type="text" placeholder="Email Address" class="input-icon-email cly-pvxl" name="email"> </div> ...

Toggle the visibility of the route layer in Leaflet by clicking on a button using the Easy Button plugin

I am working on a Leaflet map that includes a button (utilizing the Easy Button plugin from https://github.com/CliffCloud/Leaflet.EasyButton). Upon clicking this button, a route layer is added to the map using the Leaflet Routing Machine plugin (https://gi ...

Using Javascript in .NET to restrict the number of characters allowed in a textbox during typing and pasting

Consider this situation: I am attempting to display the indication "XY characters left" and restrict characters in a textbox as the user types. However, since I also have multiline textboxes, MaxLength doesn't always suffice (don't worry, I vali ...

What is the process of extracting a utility function from a helper file on a node.js server?

I'm facing a challenge with my node/express server where I need to access a function from a helper file in my app.js. The function in the helper file looks like this: CC.CURRENT.unpack = function(value) { var valuesArray = value.split("~"); ...

Show only specific data from JSON results

I am trying to display a specific cryptocurrency's price without the need for curly braces or explicitly stating "USD". Currently, it appears as {"USD":0.4823} when using the following code: <script> $(document).ready(function () { ...

Managing the Response from Google Geocode API in a Vue JS Component

I am facing an interesting challenge. I have a scenario where users can choose between two options - using their current location or entering a zip code. When a user inputs a zip code, I need to make a call to the Google geocode API to retrieve the central ...

Preventing JQuery spinner from resetting the value based on the set step size

Is it possible to set the jQuery spinner to increment by 5 but start at an initial value of 1, then proceed with increments of 5 (resulting in values such as 6, 11, and so on)? Currently, when I define a step of 5, the spinner seems to ignore the initial v ...

Is there a way to display "not found" if the code's output is blank?

Incorporating an "ajax select" and "while scrolling load data" script has been successful for me. However, I'm struggling with displaying a "not found data" message in div.status when the output variable on animals.php is empty. index.html <!DOCT ...

Leveraging onClick in combination with React's AutoBind

Just started learning React, so please point me towards documentation if I missed anything. I'm attempting to initiate an Ajax call using the onClick method following a tutorial on React. See the code snippet below. doSomething: function() { // ...

What is the proper location to insert CSS within Laravel?

What is the recommended location for storing CSS or JS files in Laravel? More specifically, what are the differences between placing CSS files in /public versus /resources/css? Which directory is preferable for storing my CSS files? ...

Copy the chosen items from the list and paste them into the textarea, then include any

After reading this post about selecting elements from a list in Angularjs and displaying them in a textarea I am interested in implementing the following new features: Automatically populate the textarea with selected elements from the list. Allow the u ...