This question already has answers here:
Using CSS to affect div style inside iframe
(14 answers)
Closed 1 year ago.
I have an <iframe> tag.
I don't know how to add content to that <iframe>
example:---
<iframe id="iframe" src="https://musafiroon.github.io/stackoverflow/index.html" width="200"/>
at https://musafiroon.github.io/stackoverflow I have made 3 elements with attribute class="text"
I want to color all these text blue in my Iframe.
how should I do this?
I am working on my pc with some HTML files inside a folder
Does the iframe src url belong to the same origin as the main page? Are they accessed by the same domain name?
If the main page and the iframe content share an origin
Javascript and same origin iframes
Otherwise
You'll need to change something so they share an origin. You can put the iframe content behind a proxy so it shares the main page's origin. If your main page is a dynamic site, you can add a new endpoint (e.g. /iframe), and in the request handler (on the server side) you request your iframe content and return it. Alternatively, you can use a CDN service like AWS CloudFront or Akamai to combine the main page and the iframe content domains into a single domain. You would configure it so that requests to /iframe/* are served by your-iframe-content.com/*, and all other requests are served by your main content server. Explanation for CloudFront
You can't edit the content of an iframe tag.
I feel you can change color of the content in the iframe by defining color of the class--text in the source file "index.html".
You can set the color of the content in iframe as per below code..
<style>
.text{
color:blue;
}
</style>
with your main code.
Related
I want to change styles css inside at a iframe, using:
$("#box_close").click(function(){
("#iframe").contents().find("#scrolling_box").removeClass("scrollingBox");
$("#iframe").contents().find("#scrolling_box").addClass("scrollingBoxCustom");
});
Not working ok because the attribute src is in different host that index file, so it gives a classic browser policy error when trying to access a resource that is not on the same host.
Is there some another way I can change styles from the html content of an iframe from a page hosted on another server?
Thanks,
I am working on a Project with an IFrame. Here is my question:
I want to take the css and Stylesheet from my Website into an iframe. The Content of the iframe is from another Domain, but I have full access to this Domain. The parentpage of the iframe has only simple html Content without any Stylesheet or css.
How can I make this work? Is it possible to write a script in both pages to adjust the css of the iframe?
Other questions and Solutions are about the same Domain or cross Domain without access to the parentpage of the iframe-content.
Thanks for the answers.
Marcel Mutz
Even if YOU have access to the other domain, that does not mean you can overcome the same-origin policy setup in the browser. You won't be able to change the styling in the iframe if the contents of that iframe originates in another domain.
More info from Mozilla
Currently we are trying to access the HTML of (with javascript) dynamically generated html-elements (e.g. to get the url of an image). If the html-elements are generated with javascript only - their is no problem. Just extracting the image url with javascript by accessing the DOM elements. But now we have trouble with an iframe.
This is the situation at the moment:
We include external script-file (www.test.com/script.js) to create a gallery on our website
The script.js generates a new iframe in our website (document.write('iframe code here')); referencing to www.test.com/iframe.html)
The iframe.html contains javascript-code again to generate the gallery by creating serveral dom-elements (divs, imgs, a, p,....)
Now we need to read the src-attribute of these images. With the debugging tool of the browser, it is no problem. Without the iframe, it's also no problem. But with the iframe, because of the cross domain policy of the browsers we can not access the html of the iframe.html with javascript.
One possible solution was to try to get the src of the iframe tag with javascript, call a server-side script to get the html content of the src-url and run the content via eval()-function on the client again.
I hope you have other better ways to solve that.
It is not clear from your question, but if the iframe is being served by your app, you can use postMessage in order to communicate between the iframe and its parent window.
so I have an iframe:
<iframe id="CPHNavBar_TBDC081D1008_frameSticky" src="/stickyserviceavailabilitycheck"></iframe>
and I need to reference a piece of css code that lives on the src portion above. This code will select it when on the src page:
document.getElementById( "ContentPlaceHolder1_C001_btnSMBAddressCheckYes");
Is it possible to reference the css element from page with the
<iframe id="CPHNavBar_TBDC081D1008_frameSticky" src="/stickyserviceavailabilitycheck"></iframe>
hosted on it?
Due to the Same Origin Policy, if two pages do not share a domain name and port number, one page cannot edit the DOM, or run JS on the other page. (Usually attempted via the <iframe> element). The same origin policy also applies to XMLHttpRequest.
This question already has answers here:
Cross domain iframe issue
(5 answers)
Closed 6 years ago.
I am embedding a script via <script src="example.com/file.js"></script> on a domain that does not belong to me. The script outputs a iframe with its src set to a script on my site. I'm also outputting a div tag that contains the iframe (it is not rendered by the iframe but the js file). Now, I want to be able to execute a function that is loaded via the iframe to control the parent div of the iframe OR output the function along with the div tag and execute the function from the iframe. I am getting permission denied errors when attempting to do either. How can I grant permission?
You can't (and then time passes and the answer changes, see the duplicate question).
In short, you can't using the way you posted. The only thing windows (including iframe windows) can do to each other is change the URL / hash. What you can do is:
1) Make an HTML page that checks its hash for commands to run. Put this on SITEA.
2) On your regular SITEA page load SITEB in an iframe.
3) SITEB iframes doesn't have access to it's parent since it's on a seperate domain. However, it can load the page you set in step 1 through an iframe. You can also change the URL on this iframe. This SITEA iframe is allowed to talk and control SITEA parent (through something like window.top).
This may sound confusing but it works and is pretty much the only way to do it cross-browser and in IE6. I've done stuff like this to support ads that expand on the parent site.